seekg() Function - NayiPathshala

Breaking

Total Pageviews

Loading...

Search Here

11/21/2017

seekg() Function

In the C++ programming language, seekg() is a function in the fstream library that allows you to seek to an arbitrary position in a file.

istream& seekg ( streampos position );
istream& seekg ( streamoff offset, ios_base::seekdir dir );
position is the new position in the stream buffer. This parameter is an object of type streampos.
offset is and integer value of type streamoff representing the offset in the stream's buffer. It is relative to dir parameter.
dir is the seeking direction. It is an object of type ios_base::seekdir that can take any of the following constant values:
ios_base::beg (offset from the beginning of the stream's buffer).
ios_base::cur (offset from the current position in the stream's buffer).
ios_base::end (offset from the end of the stream's buffer).
fstream.h is a standard C++ library that handles reading and writing to files either in text or in binary formats. It is an object oriented alternative to C's FILE from the C standard library. fstream is the result of a multiple inheritance with ifstream and ofstream, which both inherit from ios.
#include

int main()
{
    std::ofstream file;
    file.open("file.txt");
    file << "Hello world!\n";
    file.close();
}

No comments:

Post a Comment