Open a file for output then write to that file : fstream « File Stream « C++ Tutorial






#include <fstream>
#include <iostream>
using namespace std;
   
int main () 
{
  char buffer[256];
 
  // open it for output then write to it
  fstream myfile;
  myfile.open("test.txt",ios::out | ios::trunc);

  if (myfile.is_open())   {
     myfile << "This outputting a line.\n";
     myfile.close();
  }
 
  return 0;
}








12.8.fstream
12.8.1.Open a file for output then write to that file
12.8.2.Reverse a file
12.8.3.Use fstream to read and write a file.
12.8.4.change a file by offset