I wanted to know if I can delete the values (string or int) written in a file from main. i.e. erase开发者_如何学Go entire data in a text file and make it empty like before If yes, how?
Just overwrite it with a new, empty file:
#include <fstream>
std::ofstream ofs("myfile.txt");
ofs.close();
You can use ios_base::trunc
openmode with ofstream:
(truncate) Any current content is discarded, assuming a length of zero on opening.
Example,
std::ofstream ofile("filename.txt", ios_base::trunc);
//work with ofile
ofile.close();
精彩评论