write to file
hi,
im trying to write a string in the 3rd line without writing or deleting any string in the 1st and 2nd line
e.g.
1 2 3 4
|
line 1
line 2
line 4
|
i tried
1 2 3 4 5 6 7 8 9
|
ofstream w("txt.txt");
if(w)
{
w << "";
w << "";
w << "\n\nline 3";
w.close();
}
|
it didnt work
the output should be
line 1
line 2
line 3
line 4 |
is there a right way to do it ??
thanks in advance.
Last edited on
When you start writing to the file you will overwrite the old file.
is there a possible way if i could just parse the 1st 2 lines then write it back along with the 3rd line string
e.g.
1 2 3 4 5 6 7 8 9 10 11
|
string line1, line2;
fstream w("txt.txt" );
getline(w, line1);
getline(w, line2);
w << line1;
w << line2; // this dont work
w << "line3";
w.close();
|
something like that
Topic archived. No new replies allowed.