Removing Characters from a File

感情迁移 提交于 2019-12-02 04:38:11

问题


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.
}

回答1:


You have two options:

  1. Read the entire file in the memory, then save it to the file excluding unwanted parts.
  2. Copy the source file to newly created file excluding unwanted parts, remove the source file, then rename second file.


来源:https://stackoverflow.com/questions/5503863/removing-characters-from-a-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!