Is it possible to read and to write to a file at the same time useing that line. I have been told it is impossible to do that but i have seen tutorials out there. If it is anything i should conciderCode:fstream File(“my.txt”,ios::in | ios::out);
Is it possible to read and to write to a file at the same time useing that line. I have been told it is impossible to do that but i have seen tutorials out there. If it is anything i should conciderCode:fstream File(“my.txt”,ios::in | ios::out);
It's possible. Streams uses separate read and write pointers (seekg/p and tellg/p). I have some memory of when doing a read/write operation it will reset the other pointer so take this into consideration, but don't quote me on this one...
If you don't need to read and write at the same time don't open it as both read-n-write.If it is anything i should concider
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
My teacher said that he tryed to do it but no luck. oo we use dev c++ if that helps beside that yah i will try thanks.
Hm, it seems that reading data clears the written data to the file. I was so sure this was possible . Anyway, your best bet would be to close then re-open the file using a new mode (read/write).
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
If you wish to append data to the end of a file, you should specify the ios::app flag, else the ostream will overwrite the existing contents of a file.
if you wish to modify a file at the beginning or "somewhere in the middle" then the only (*1) option is to create a new temporary file, in which to create the updated contents, then overwrite the old file with the updated one.
*1 - Of course, there might be nonstandard extentions which achieve this using some other method, this is the only way to do it with standard C++.
Thanks Yah thats what i have been told