fork(2) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <sstream>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. string command, intermediate,temp;
  10. getline (cin,command);
  11. vector <string> tokens;
  12. stringstream check(command);
  13. string middle;
  14. while(getline(check, intermediate, ','))
  15. {
  16. tokens.push_back(intermediate);
  17. }
  18.  
  19. for(int i = 0; i<tokens.size(); i++)
  20. {
  21. cout << tokens[i] <<endl;
  22.  
  23. }
  24. cout << tokens.size() << " elements:"<<endl;
  25. if (tokens.size()>1)
  26. temp = tokens[1];
  27. else temp = "Second element not found";
  28. cout<<temp<<endl;
  29.  
  30. string tmp;
  31. for (auto const& x:tokens)
  32. tmp += x+" ";
  33. cout << tmp<<endl;
  34. return 0;
  35. }
Success #stdin #stdout 0s 15240KB
stdin
hello,world, what's new?
stdout
hello
world
 what's new?
3 elements:
world
hello world  what's new?