从文件中删除字符 [英] Removing Characters from a File
本文介绍了从文件中删除字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何删除文件中的任意字符(而不用某些东西代替)?
How can arbitrary characters be removed (not replaced by something) in a file?
#include <fstream>
int main()
{
std::fstream FileStream("MyFile.txt", ios_base::in | ios_base::out | ios_base::binary);
// For the sake of argument, MyFile.txt already has stuff in it.
FileStream.seekg(5);
FileStream.remove(); // Something like this.
}
推荐答案
您有两个选择:
- 读取内存中的整个文件,然后将其保存到文件中(不包括不需要的部分).
- 将源文件复制到新创建的文件(不包括不需要的部分),删除源文件,然后重命名第二个文件.
这篇关于从文件中删除字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文