fork(1) download
  1. #include <iostream>
  2.  
  3. int main() {
  4. int number;
  5. std::cin >> number; //read from keyboard
  6. std::cout << number; //save to file
  7.  
  8. std::ifstream in("newinput.txt");
  9. std::cin.rdbuf(in.rdbuf());
  10. std::ofstream out("newoutput.txt");
  11. std::cout.rdbuf(out.rdbuf());
  12.  
  13. std::cin >> number; //read from newinput.txt
  14. std::cout << number; //write to newoutput.txt
  15. }
  16.  
  17. int main() {
  18. int number;
  19. std::io >> number; //read from keyboard
  20. std::io << number; //save to file
  21.  
  22. std::fstream in("newinput.txt", std::ios::in);
  23. std::io.rdbuf(in.rdbuf()); //what gets rebound? in or out?
  24. std::fstream out("newoutput.txt", std::ios::in);
  25. std::io.rdbuf(out.rdbuf()); //what gets rebound? in or out?
  26.  
  27. //alright, so for your hypothetical example, we replace with `rdbufin` and `rdbufout`
  28. std::fstream in("newinput.txt", std::ios::in);
  29. std::io.rdbufin(in.rdbufin());
  30. std::fstream out("newoutput.txt", std::ios::in);
  31. std::io.rdbufout(out.rdbufout());
  32.  
  33. std::ifstream in2("infile2.txt");
  34. in2.rdbufout(in2.rdbufout()); //What part of this makes sense?
  35. // ergo, std::io cannot be like a `std::ifstream`
  36. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:8:21: error: variable 'std::ifstream in' has initializer but incomplete type
prog.cpp:10:22: error: variable 'std::ofstream out' has initializer but incomplete type
prog.cpp: In function 'int main()':
prog.cpp:17:5: error: redefinition of 'int main()'
prog.cpp:3:5: error: 'int main()' previously defined here
prog.cpp:19:5: error: 'io' is not a member of 'std'
prog.cpp:20:5: error: 'io' is not a member of 'std'
prog.cpp:22:20: error: variable 'std::fstream in' has initializer but incomplete type
prog.cpp:23:5: error: 'io' is not a member of 'std'
prog.cpp:24:21: error: variable 'std::fstream out' has initializer but incomplete type
prog.cpp:25:5: error: 'io' is not a member of 'std'
prog.cpp:29:5: error: 'io' is not a member of 'std'
prog.cpp:31:5: error: 'io' is not a member of 'std'
prog.cpp:33:22: error: variable 'std::ifstream in2' has initializer but incomplete type
stdout
Standard output is empty