AbigailBurstein (0)

Write a program, containing 3 functions that will ask the user for his or her email address and print out the
● The user's name or ID
● The user's character site type. Display the specific name for all 3-character site types.

I am at lost!

You are viewing a single comment. View All
mwilki7 (1078)

cout << "Your user Id is :" << ID;
ID was never declared anywhere

Strings in C++ don't have an 'IndexOf' function. In this case, you'd use find()

For example:

string test = "test";
int test_index = test.find('s');
cout << "'test' index of 's': " << test[test_index] << endl;

string domain = e_mail.Substring(indexOfAt + 1);
C++ uses 'substr' as the function name for substring.
You may have noticed the naming convention for C++ libraries is lowercase
('find' instead of 'Find', 'substr' instead of 'Substr' etc...).

AbigailBurstein (0)

How do I get it to print out the In general, the part before the name or ID of a particular user, and the part after the @ specifies the site at which the user is [email protected]

mwilki7 (1078)

You can use find() to search for the '@' and that will give you the index of that symbol. Then use that index to print everything before it or after it.

For example:

string email = "[email protected]"
int at_index = email.find("@");

cout << "Before @: " << email.substr(0, at_index) << endl;
cout << "After  @: " << email.substr(at_index + 1, email.length() - 1) << endl;

you may need to add or subtract 1 to at_index in the substr function, I don't know if substr is "up to index" or "up to and including index".