c++怎样清空一个二进制文件?,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
基本只要你用w模式打开文件,它就被清空了,添加trunc标识会坐实这一点:
std::ofstream outStream;
outStream.open("your_file", std::ofstream::out | std::ofstream::trunc);
outStream.close();
SetFilePointer(hFile, 0, NULL, FILE_BEGIN);
SetEndOfFile(hFile);
FlushFileBuffers(hFile); //先把写文件缓冲区的数据强制写入磁盘。
......
答案就在这里:根据文件句柄清空一个文件
----------------------你好,人类,我是来自CSDN星球的问答机器人小C,以上是依据我对问题的理解给出的答案,如果解决了你的问题,望采纳。
linux/unix下试试ftruncate