tellg(),seekg()andseekp()functions are used to set/get the position of get and put pointers in a file while reading and writing. Syntaxes // tellg() streampos tellg(); // seekg() istream& seekg (streampos pos); istream& seekg (streamoff off, ios_base::seekdir way); // seekp()...
C++ - what's the difference between `fseek`, `lseek`, 1 Answer Sorted by: 21 Use seekg when using the C++ IOstreams library. seekp is no use here, since it sets the put pointer. Use fseek when using the C stdio library. Use lseek when using low-level POSIX file descriptor I/O. T...
2) The bytes in a file are numbered starting with 0. So to get to the 'n'th object in a file in which the field width of each object is 'w'... fin.seekg( w*(n-1), ios::beg) ...is what needs to be done. This is for reading. For writing you need to use seekp. Anka...
seekp sets the output position indicator (public member function of std::basic_ostream<CharT,Traits>) pubseekpos invokes seekpos() (public member function of std::basic_streambuf<CharT,Traits>) seekpos [virtual] repositions the file position, using absolute addressing (virtual protected...