I want to search for a string in a text file and delete the whole line when it's found. I want to write this in C++.
I've tried solutions in C#, and I've tried creating temporary files. Nothing works for me.
Here's my code so far:
void MainForm::WriteToTextFile(){
ifstream stream("text.txt");
string line;
bool found = false;
while (std::getline(stream, line) && !found)
{
if (line.find("Delete_This_Line") != string::npos){ // WILL SEARCH "Delete_This_Line" in file
found = true;
line.replace(line.begin(), line.end(), "\n");
stream.close();
}
I expected that the text file would be modified but nothing has changed.