Nuz25
Junior Member
- Aug 20, 2010
- 129
- 100
Ok guys I have an exam (C/C++) tomorrow and I have this simple question that's pissing me off right now...
" You have the binary file "INTEGERS.DAT" containing only integers. Write the declarations and instructions to open the file and affect the value zero to the penultimate integer of the file without rewriting the rest of the file. "
Here's the given answer:
int zero = 0;
fstream file;
file.open("INTEGERS.DAT", ios::binary|ios::in|ios:: out);
if(!file.fail()){
file.seekp(-1*sizeof(int),ios::end);
file.write((char*)&zero, sizeof(int));
file.close();
}
But shouldn't it be :
int zero = 0;
fstream file;
file.open("INTEGERS.DAT", ios::binary|ios::in|ios:: out);
if(!file.fail()){
file.seekp(-2*sizeof(int),ios::end);
file.write((char*)&zero, sizeof(int));
file.close();
}
?????????????????????
" You have the binary file "INTEGERS.DAT" containing only integers. Write the declarations and instructions to open the file and affect the value zero to the penultimate integer of the file without rewriting the rest of the file. "
Here's the given answer:
int zero = 0;
fstream file;
file.open("INTEGERS.DAT", ios::binary|ios::in|ios:: out);
if(!file.fail()){
file.seekp(-1*sizeof(int),ios::end);
file.write((char*)&zero, sizeof(int));
file.close();
}
But shouldn't it be :
int zero = 0;
fstream file;
file.open("INTEGERS.DAT", ios::binary|ios::in|ios:: out);
if(!file.fail()){
file.seekp(-2*sizeof(int),ios::end);
file.write((char*)&zero, sizeof(int));
file.close();
}
?????????????????????