Moved the question here. Suppose I want to store 1,000,000,000 integers and cannot use my memory. I would use a file (which can easily process so much data). How can I let him read and write at the same time. Using fstream file("file.txt', ios::out | ios::in ); does not create the file in the first place. But assuming the file exists, I cannot use read and write at the same time. What do I have in mind: Let the contents of the file 111111 Then, if I ran: -
#include <fstream> #include <iostream> using namespace std; int main() { fstream file("file.txt",ios:in|ios::out); char x; while( file>>x) { file<<'0'; } return 0; }
Should the contents of the file 101010 ? Read one character and then overwrite the next one with 0? Or was all the content read right away in some kind of buffer if there should not be a single 0 in the file? 1111110 ? But the content remains unchanged. Please explain. Thanks.
source share