fork download
  1. #include <iostream>
  2. #include <sstream>
  3. #include <string>
  4. using namespace std;
  5.  
  6. int main() {
  7. const string str("(844)615-4504 Sofia Ross 57");
  8.  
  9. string pn, fn, ln, age;
  10. std::size_t loc = str.find(' ');
  11. if(loc == string::npos) return 1; // bad string
  12. pn = str.substr(0, loc - 1);
  13. std::istringstream iss(str.substr(loc));
  14. iss >> fn >> ln >> age;
  15.  
  16. cout << "Phone: " << pn << endl;
  17. cout << "First: " << fn << endl;
  18. cout << "LastN: " << ln << endl;
  19. cout << "Age : " << age << endl;
  20. return 0;
  21. }
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
Phone: (844)615-450
First: Sofia
LastN: Ross
Age  : 57