fork download
  1. #include <iostream>
  2. #include <sstream>
  3. #include <string>
  4.  
  5. int main()
  6. {
  7. std::string s;
  8.  
  9. std::cout << "Input a number: ";
  10. std::getline(std::cin, s);
  11.  
  12. std::stringstream ss(s); // construct string stream from existing string data
  13. int n;
  14.  
  15. ss >> n;
  16. std::cout << "Number was: " << n << '\n';
  17. }
  18.  
Success #stdin #stdout 0s 2988KB
stdin
-6223 abracadabra
stdout
Input a number: Number was: -6223