2) I load the whole file into a string (C++ String)
Ok, so apparently you have something like this:
Code:
string str = "line1\nline2\nline3";
3) I search the string for a certain piece of text and get the index.
int pos = str.find('n');
4) I use the string's replace method to put my new string in place of the old string
Code:
if(pos != string::npos)
{
str.replace(pos, 1, "hello world");
}
Then I assume your write the string back to the file. Where does the overwriting of the beginning of the next line happen?