I am saving 100,000 integers to a binary file using:
for(unsigned int i = 0; i < 100000; i++){
temp = generateRand(99999);
file.write(reinterpret_cast<const char*>(&temp),sizeof(temp));
}
and from this file, I'm trying to read integers, and save them into a vector.
ifstream ifile;
ifile.open("test.bin",ios::binary);
ifile.seekg(0, ifile.end);
long size = ifile.tellg();
ifile.seekg(0, ifile.beg);
int restore = 0;
int count = 0;
while(ifile.tellg() < size){
ifile.read(reinterpret_cast<char*>(&restore), sizeof(restore));
v.push_back(restore);
count++;
}
However it seems like I can only read 99328 integers, not 100000. I am relatively new with read/write with binary files, so can you guys help me?
temp? what is the size of the file you get? how do you define/openfileandifile?filebefore reading?