fork download
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4.  
  5. int main() {
  6. // Write C++ code here
  7. ofstream MyFile("file_name.txt");
  8.  
  9. MyFile << "Files can be tricky, but it is fun enough!";
  10.  
  11. MyFile.close();
  12.  
  13. string myText;
  14.  
  15. ifstream MyReadFile("file_name.txt");
  16.  
  17. while (getline (MyReadFile, myText))
  18. {
  19. // Output the text from the file
  20. cout << myText;
  21. }
  22.  
  23. MyReadFile.close();
  24.  
  25. return 0;
  26. }
Success #stdin #stdout 0.01s 5272KB
stdin
Standard input is empty
stdout
Standard output is empty