hi,
I have a file text:
I need change the first line to "goodnight". But how do I have to open file? in append mode it it goes at the end; out mode it'll destroyed.....Code:hello house sunrise down
thanks
hi,
I have a file text:
I need change the first line to "goodnight". But how do I have to open file? in append mode it it goes at the end; out mode it'll destroyed.....Code:hello house sunrise down
thanks
You have to read in the entire file, and write it back out with the lines changed that need changing. One way to do this is to read in the file, store the data in a data structure, then open the file for writing (which truncatesthe whole thing) and write out the data in the data structure. At some point you would change what you needed to change.
Another solution is to read one item at a time and write to a temporary file. Then when you are done delete the original file and rename the temporary one.
This page may be helpful ??? Input/Output with files
sorry, but my question want says without copy the file the data in a file; I just say: overwrite a file text line. Is it possible?
Not really. If your file was binary and setup as a series of fixed lengths records, then you could do it by seeking to the place you want to modify and then writing the new, proper fixed length string. However, you are using a text file and the common way to do this with a text file is one of the two methods I mentioned above.
how can I delete a file in c++?
With the remove() or unlink() CRT function.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law