overwrite text file data?

Mar 21, 2011 at 10:16pm
Can someone tell me how do I overwrite the first data on the text file? What function do I have to use? I have tried to use the ios::beg but there was an error with it.. Why can I not do like this?

are.open("student_data.txt",ios::beg);
Mar 21, 2011 at 10:18pm
are.open("student_data.txt", ios::trunc);
This should work.
Mar 21, 2011 at 10:33pm
If you simply open it and don't call the ios::app flag, the data will be overwritten.

file.open("file.ext",ios::out);
Last edited on Mar 21, 2011 at 10:33pm
Mar 21, 2011 at 11:46pm
Correct me if I am wrong, ios::trunc and ios::out will delete all the data in the text file. Is it?

I am sorry for not being clear in here. I only want to overwrite the first data in the text file without altering other data.
(What I mean data here is a list of data)
Mar 21, 2011 at 11:48pm
Waaaait so you want to simply put data in, and override the data that is currently in that position, but leave the rest completely unaffected?
Mar 22, 2011 at 12:48am
Basically that is the idea. By the way, I find a way to overwrite the first data,

are.open("student_data.txt",ios::in);
are.seekp(0,ios::beg); //overwrite only the beginning of the list (1st data)



Then the second problem is I need to figure out how to overwrite the second data on the list without affecting the rest of the data again. Any idea how? I am trying to do the 'for' loop, but I don't think it make sense.
Topic archived. No new replies allowed.