Could someone please help me with the following code:
Inout_file.seekp(((long)-1 * sizeof(int)), ios::cur);
// offset // // mode//
This code is used to move the offset back 4 bytes from the 12th byte after replacing a value in the list. The above offset is -4 in order to move the offset back and this results in the offset now being at the 8th byte. I cant understand why the offset is -4 though. Is this to do with the ‘long’ and what is the -1 for?. Also this code is worked on the basis that integers are 4 bytes.
Hope that anyone can help…thanks
Re: negative offset
The seekp member function sets this pointer and thus provides random-access disk file output.
Now about the code You are passing the first parameter as
-1 * sizeof(int)
-1 * 4 [As you have told integer is 4 bytes]
And so the result becomes
-4 and so seekp moves the pointer 4 bytes in the reverse direction and so it moves from 12th to 8th byte.
|All times are GMT +5.5. The time now is 02:15.|