I am writing numbers from array to binary file, but somehow when I print file last number printing twice. I not sure is it problem with how I write or how I read.
This is how I write to the file
for (int k = i - 1; k>-1; k--) {
file2.write(reinterpret_cast(&arr[k]), sizeof(int));
}
This how I read and print from the file
while ( file2 ) {
int val;
file2.read(reinterpret_cast(&val), sizeof val);
cout << val << endl;
}
So, if array of numbers is 31 29 47, printing file will give
47
29
31
31
No comments:
Post a Comment