从文件中删除特定行的函数 [C++11]

问题描述

我尝试编写一个函数,从结构文件删除 B 配置(a、b、c 也是如此)

示例文件

A:
   a=1
   b=2
   c=3
B:
   a=1
   b=2
   c=3
C:
   a=1
   b=2
   c=3

所以我写:

if(std::ifstream file{path}){
        std::string line;

        while(std::getline(file,line)){
            
            //remove whitespaces
            line.erase(std::remove_if(line.begin(),line.end(),::isspace),line.end());


            if(line == "B:"){

                for(size_t i= 0; i < 3; i++){
                    std::getline(file,line);
                    line.erase(std::remove_if(line.begin(),line.end());
                    std::string phrase(line,1);

                    if(phrase == "a" || phrase == "b" ||  phrase == "c"){
                        /*
                         *
                         *
                         */
                    }
                }
            }
        }
            
     }else{
         std::cout << "[ERROR] Cant open file\n";
     }
}

我只是不知道输入什么来删除给定的行

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)