我是一名初学者,是C ++的新手,并且希望学习。这是我到目前为止的内容:
这是教师提供给我的伪代码版本:
if str.find("@")==string::npos OR <-- @ not found
str.find(".")==string::npos OR <-- . not found
str.find(" ")!=string::npos) <-- space found
我对功能要求的理解:
check emails for @, ., or space function,
if @ exists, no output
if @ doesn't exist, output "This (email) is invalid."
if . exists, no output
if ' ' exists, output "This (email) is invalid."
这是对不起的尝试,不起作用:
void Roster::printIncorrectEmails()
{
char at = '@';
char pd = '.';
char sp = ' ';
for (int i = 0; i < sizeof(RepoArray); i++) {
string email = Student::RepoArray.getEmailAddress();
size_t found = email.find(at, pd);
if (found != string::npos)
{
cout << "Invalid Email: " << email << '\n';
}
found = email.find(sp);
if (found == string::npos)
{
cout << "Invalid Email: " << email << '\n';
}
}
}
如果有人愿意看到我,我也有很多其他尝试。