C++/OOP
Expert: Prince M. Premnath - 11/23/2006
Question
Write a statement that moves the get pointer 13 bytes backward from the current position in a stream object called f1.
thanks. .
AnswerDear Rikin!
There are two member functions to move the file pointer to the desired location in a file
seekg(offset , refposition);
seekp(offset , refposition);
The parameter offset refer to the number of bytes th file pointer to be moved from the position referred by the parameter refposition ,
the available constants for refposition are .
1. ios::beg beginning of a file
2. ios::cur from the current position of the pointer
3. ios::end End of the file.
*The seekg() function associate with the file's 'get' pointer , where as seekp() for file's put pointer
Here is the options allowed for seekg() function.
f1.seekg(0 , ios::beg); moves pointer to the beginning
f1.seekg(0 , ios::cur); stay current position
f1.seekg(0 , ios::end); move to end
f1.seekg(n , ios::beg); move(n+1) bytes from the beginning
f1.seekg(n , ios::cur); moves n bytes forward from the current position
f1.seekg(-n , ios::cur); moves n bytes backward from the current position
f1.seekg(-n, ios::end); move n bytes backward from the end
* So inorder to move 13 bytes backward from the current position in a stream object called f1 you should have to use the statement like this
f1.seekg(-13 , ios::cur);
Regards !
Prince M. Premnath
-Happy Programming.