printing invalid email entries

Hi everyone,

Currently working on the last piece of a project for school and I am stuck on how to do the following portion of it.

"e. public void printInvalidEmails() that verifies student email addresses and displays all invalid email addresses to the user


Note: A valid email should include an at sign ('@') and period ('.') and should not include a space (' ')."

I tried the following code; however, I am getting the errors below.

"repos\Class Roster\Class Roster\roster.cpp(139,7): error C3867: 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::find': non-standard syntax; use '&' to create a pointer to member
repos\Class Roster\Class Roster\roster.cpp(139,7): error C2109: subscript requires array or pointer type"

if anyone has any incite on how to make this work that would be very helpful.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
  void Roster::printInvalidEmailEntries()
{
	bool any = false;
	for (int i = 0; i <= lastIndex; i++)
	{
		any = false;
		string eAddress = student[i]->getemailAddress();
		for (int j = 0; j <= lastIndex; j++)
		{
			if (eAddress.find[j] == " ")
			{
				any = true;
				cout << "Student ID" << student[i]->getstudentID() << ": ";
				cout << eAddress[j] << " ";
			}
			else if (eAddress.find[j] != "@")
			{
				any = true;
				cout << "Student ID" << student[i]->getstudentID() << ": ";
				cout << eAddress[j] << " ";
			}
			else if (eAddress.find[j] != ".")
			{
				any = true;
				cout << "Student ID" << student[i]->getstudentID() << ": ";
				cout << eAddress[j] << " ";
			}
		}
		if (any) cout << "\n";
	}
	if (!any) cout << "NONE";
}
Have you looked up documentation for the find function?

http://www.cplusplus.com/reference/string/string/find/
https://en.cppreference.com/w/cpp/string/basic_string/find

Both links contain examples. If you're looking to see if the string contains, e.g. an @ symbol, then you need do something like:
1
2
3
4
5
string address = "blah@blah@@@@";
if (address.find("@") != string::npos)
{
    cout << "@ sign found!\n";
}

PS:
Note: A valid email should include an at sign ('@') and period ('.') and should not include a space (' ')."
Is ".aaaf@bbb" a valid email address?
Last edited on
Is ".aaaf@bbb" a valid email address?

According to the instructions yes.
Topic archived. No new replies allowed.