C++ clear data in text file

std::ifstream File;
std::string filepath = "text.txt";
File.open(filepath.c_str(), std::ifstream::out | std::ifstream::trunc );
if (!File.is_open() || File.fail())
{
File.close();
printf(" Error : failed to erase file content !");
}
File.close();

原文地址:https://www.cnblogs.com/jieliujas/p/12220895.html