fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. std::ostream& operator<< ( std::ostream& stm, const std::string& s )
  5. { return stm << s.c_str() << " [size:" << s.size() << ']' ; }
  6.  
  7. std::istream& operator>> ( std::istream& stm, std::string& s )
  8. { return std::getline( stm, s ) ; }
  9.  
  10. int main()
  11. {
  12. std::string str ;
  13. std::cout << "enter a line containing whitespace: " ;
  14. std::cin >> str ;
  15. std::cout << "you entered: " << str << '\n' ;
  16. }
  17.  
Success #stdin #stdout 0s 2988KB
stdin
this is a test
stdout
enter a line containing whitespace: you entered: this is a test [size:14]