fork(1) download
  1. // swapping stringstream objects
  2. #include <string> // std::string
  3. #include <iostream> // std::cout
  4. #include <sstream> // std::stringstream
  5.  
  6. int main () {
  7.  
  8. std::stringstream foo;
  9. std::stringstream bar;
  10.  
  11. foo << 100;
  12. bar << 200;
  13.  
  14. foo.swap(bar);
  15.  
  16. int val;
  17.  
  18. foo >> val; std::cout << "foo: " << val << '\n';
  19. bar >> val; std::cout << "bar: " << val << '\n';
  20.  
  21. return 0;
  22. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:13:3: error: expected ‘;’ before ‘int’
   int val;
   ^
prog.cpp:15:3: error: ‘foo’ was not declared in this scope
   foo >> val; std::cout << "ss val: " << val << '\n';
   ^
prog.cpp:15:10: error: ‘val’ was not declared in this scope
   foo >> val; std::cout << "ss val: " << val << '\n';
          ^
stdout
Standard output is empty