fork download
  1. #include <iostream>
  2. #include <fstream> // needed for file I/O
  3. using namespace std;
  4.  
  5. int main() {
  6. ofstream outFile; // create output file object
  7. outFile.open("results.txt"); // open a file for writing
  8.  
  9. outFile << "Hello, file!" << endl; // write to file
  10. outFile << 42 << endl;
  11.  
  12. outFile.close(); // close the file
  13. return 0;
  14. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty