writing on a text file : Text File « File « C++






writing on a text file

  
#include <iostream>
#include <fstream>
using namespace std;

int main () {
  ofstream myfile ("example.txt");
  if (myfile.is_open()){
    myfile << "This is a line.\n";
    myfile << "This is another line.\n";
    myfile.close();
  }
  else 
    cout << "Unable to open file";
  return 0;
}
  
    
  








Related examples in the same category

1.Use the getline function with the C++ string classUse the getline function with the C++ string class
2.Write strings to disk
3.Write string to a file
4.Write to file: ofstream
5.Read from file.Read from file.
6.Reading from a File
7.Writing to a File
8.reading a text file
9.Sequential Files