fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. int main()
  5. {
  6. constexpr char seperators[] = " ,.\t" ;
  7.  
  8. const std::string full_name = "Nicolai M. Josuttis" ;
  9. std::cout << "full name: " << full_name << '\n' ;
  10.  
  11. auto pos = full_name.find_first_of(seperators) ;
  12. if( pos != std::string::npos )
  13. {
  14. const std::string first_name = full_name.substr(0,pos) ;
  15. std::cout << "first name: " << first_name << '\n' ;
  16. }
  17.  
  18. pos = full_name.find_last_of(seperators) ;
  19. if( pos != std::string::npos )
  20. {
  21. const std::string last_name = full_name.substr(pos+1) ;
  22. std::cout << "last name: " << last_name << '\n' ;
  23. }
  24. }
  25.  
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
full name: Nicolai M. Josuttis
first name: Nicolai
last name: Josuttis