Manipulation of text files in C++
Hi!
Could anyone tell me how I can add one line to the beginning of a text file using C++? I know how to open/close/read from a text file, I just want adding one line without affecting any other content in the file.. Thank you for your time. |
I don't know if it can be done in other way, but one possibility is:
1.- open file.txt for reading and file.txt.bak for writing 2.- write a "\n" to file.txt.bak 3.- copy the content 4.- close the files 5.- remove file.txgt 6.- rename file.txt.bak to file.txt step 5 shouldn't be very difficult. you only have to read from one file (which you know how to do) and write to the other, while the first file still has something inside. |
I think he meant `one line', not `one newline', but that's a minor issue.
you could also do something along the lines of (pseudo-code): Code:
stringbuffer b; |
OK!
Thank you guys for your help! |
Your pseudo-code looks a lot like python ;-)
|
Quote:
|
All times are GMT -5. The time now is 11:53 PM. |