C++ Запис

2075 / C++ / Запис в файл

 

#include <fstream>

ofstream myfile("1.txt");
if (myfile.is_open())
{
  myfile << "Line 1\n" << endl;
  myfile << "Line 2\n";
  myfile.close();
}
else cout << "Open failed";
 
 
 
Дописати в файл

ofstream myfile("1.txt", ios_base::app);
 
  
Очистити файл

ofstream ofs;
ofs.open("1.txt", ofstream::out | ofstream::trunc);
ofs.close();
 
 
 
Запис в три файли одночасно