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

#include <fstream>

 ofstream myfile("1.txt"); 

 if (myfile.is_open()) 

 { 

 myfile << "Лінія.\n" << endl; 

 myfile << "Настпна лінія.\n"; 

 myfile.close(); 

 } 

 else cout << "Не можу відкрити файл"; 

Дописати в файл

ofstream myfile("1.txt", ios_base::app);

Очистити файл

ofstream ofs; 

ofs.open("1.txt", ofstream::out | ofstream::trunc); 

ofs.close();