fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4. using namespace std;
  5. int main(int argc, char *argv[])
  6. {
  7. string line;
  8. while(getline(cin, line )) {
  9. cout << line<<" ---> ";
  10. istringstream is(line);
  11. string hi;
  12. double hello;
  13. is >> hello;
  14.  
  15. if (!is)
  16. {
  17. //Strings go here
  18.  
  19. is.clear();
  20. is >> hi;
  21. cout<<"str: "<< hi << endl;
  22. }
  23. else
  24. {
  25. cout <<"number: "<< hello << endl;
  26. }
  27.  
  28. }
  29. cout << "Done!" << endl;
  30. }
  31.  
Success #stdin #stdout 0s 4280KB
stdin
123
123abc456
-123
+123
xyz
/123
++123
+ 123
++++123abc234



stdout
123 ---> number: 123
123abc456 ---> number: 123
-123 ---> number: -123
+123 ---> number: 123
xyz ---> str: xyz
/123 ---> str: /123
++123 ---> str: +123
+ 123 ---> str: 123
++++123abc234 ---> str: +++123abc234
 ---> str: 
 ---> str: 
 ---> str: 
Done!