Kodewick
Start learning →
Basic←→0 / 60

Club username

#019BasicStrings4 min

For the book club sign-up, the username is the part of the email before @: [email protected] gives amy. Write user_name(email); if there is no @, return the whole thing as it is.

Examples
user_name("[email protected]")→'amy'
user_name("bao")→'bao'
The functionstring user_name(const string &email)
main.cpp
#include <string>
using namespace std;

string user_name(const string &email) {
    auto at = email.find('@');
    if (at == string::npos) {
        // your code here: no @ found, so return the whole email
    }
    // your code here: return the part before the @
    return "";
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.