fork download
  1. // This program writes data to a file.
  2. #include <iostream>
  3. #include <fstream>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. ofstream outputFile;
  9. outputFile.open("demofile.txt");
  10.  
  11. cout << "Now writing data to the file.\n";
  12.  
  13. // Write four names to the file.
  14. outputFile << "Bach\n";
  15. outputFile << "Beethoven\n";
  16. outputFile << "Mozart\n";
  17. outputFile << "Schubert\n";
  18.  
  19. // Close the file
  20. outputFile.close();
  21. cout << "Done.\n";
  22. return 0;
  23. }
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
Now writing data to the file.
Done.