I am trying to learn C++ by writing some code by my own and very new in this field.
Currently, I am trying to read and write a 64 bit integer file. I write 64 bit integer file in following way:
ofstream odt;
odt.open("example.dat");
for (uint64_t i = 0 ; i < 10000000 ; i++)
odt << i ;
Can anybody help me how to read that 64 bit integer file (one by one) ? So, far examples I have found, that reads line by line, not one by one integer.
Edit:
ofstream odt;
odt.open("example.dat");
for (uint64_t i = 0 ; i < 100 ; i++)
odt << i ;
odt.flush() ;
ifstream idt;
idt.open("example.dat");
uint64_t cur;
while( idt >> cur ) {
cout << cur ;
}
ofstream
. If you want to write the actual binary bits to the file, you'll have to use something other than<<
. – Greg Hewgill