overwrite text file data?

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);
are.open("student_data.txt", ios::trunc);
This should work.
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
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)
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?
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.