fork download
  1. #include <string>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. string user;
  9. cout << "-> ";
  10. cin >> user;
  11. string a, b;
  12. if (size_t pos = user.find('_'); pos != user.npos)
  13. {
  14. a = user.substr(0,pos);
  15. b = user.substr(pos+1);
  16.  
  17. cout << a << "\n" << b;
  18. }
  19. else
  20. {
  21. cout << "No _ in input\n";
  22. }
  23. }
  24.  
Success #stdin #stdout 0.01s 5516KB
stdin
user_harry
stdout
-> user
harry