fork download
  1. #include <sstream>
  2. #include <iostream>
  3.  
  4. int main()
  5. {
  6. std::string input;
  7. std::stringstream stream;
  8. std::string name;
  9. double amount;
  10.  
  11. int repeat = 4;
  12. while(repeat--) // to demonstarte
  13. {
  14. std::getline(std::cin, input); // enter a name, a whitespace and a number
  15. stream.str(input);
  16. stream >> name >> amount; // problem here
  17. std::cout << "Output: " << name << " " <<amount << std::endl;
  18. stream.str( std::string() ); // or stream.str("");
  19. stream.clear();
  20. }
  21. return 0;
  22. }
  23.  
Success #stdin #stdout 0s 4460KB
stdin
Name1 100
Name2 200
Name3 300
Name4 400
stdout
Output: Name1 100
Output: Name2 200
Output: Name3 300
Output: Name4 400