How to extract the user name from an email address in C++

2 Answers

0 votes
#include <iostream>
 
int main() {
    char email[] = "username@email.com";
    char uname[32] = "";
 
    int i = 0;
    while (email[i] != '@') {
        uname[i] = email[i];
        i++;
    }
 
    std::cout << uname;
}
 
 
 
 
/*
run:
 
username
 
*/

 



answered Apr 29, 2022 by avibootz
edited Nov 4, 2022 by avibootz
0 votes
#include <iostream>

int main() {
    std::string email = "username@email.com";
    
    int i = (int)email.find('@');
    std::string uname = email.substr(0, i);
    
    std::cout << uname;
}




/*
run:

username

*/

 



answered Nov 4, 2022 by avibootz

Related questions

1 answer 148 views
1 answer 149 views
1 answer 189 views
1 answer 150 views
1 answer 167 views
1 answer 154 views
1 answer 163 views
...