I have some questions on manipulating on a file ;
a.) I am a bit confused about get and put pointer in c++. Do I show correct position of get pointer and put pointer.
MyFile . seekg ( 0 , ios :: beg ) ;
MyFile . seekp ( -10 , ios :: end ) ;
index :0 1 2 3 4 5 6 7 8 9 10 ... -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0
__________________________________________________________________
^ ^
^ ^
^ ^
get Pointer put pointer
Myfile . get ( character ) ;
MyFile . write ( SomeString, 4 ) ;
MyFile . flush ( ) ;
index :0 1 2 3 4 5 6 7 8 9 10 ... -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0
__________________________________________________________________
^ ^
^ ^
^ ^
get Pointer put pointer
i.) Are Seekg and seekp always guarentee that get an put pointer always shows correct position ?
ii.) If you know more about this topic, can you show/give me some point(s) I should be careful when I use them, ( if there is )
b.) Is
FileIN . seekg ( 1, ifstream :: cur ) ;
equal to
FileIN . seekg ( 1, ios :: cur ) ;
Platform : linux
File format : binary
a) It’s wrong. File streams maintain one file pointer, for both input and output. Both
seekgandseekpdo the same thing. The reason there are two different functions is that the interface of iostreams is generic, it can be used for devices which do have separate put and get pointers.Quote from the standard [filebuf]:
b) Yes, they are the same.
EDIT: