lundi 4 janvier 2021

Function to delete specific lines from file [C++11]

I tries to write a function that removes the B configuration from the structure file (a, b, c too)

Example file:

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

So i write:

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(), ::isspace), line.end());
                    std::string phrase(line, 0, 1);

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

I just don't know what to type to delete a given line

Aucun commentaire:

Enregistrer un commentaire