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