seekg(), tellg()

seekg()
Set position of the get pointer
Sets the position of the get pointer.
The get pointer determines the next location to be read in the source associated to the stream.

tellg()
Get position of the get pointer.
Returns the absolute position of the get pointer.
The get pointer determines the next location in the input sequence to be read by the next input operation.

[Example]
// read a file into memory
#include
#include
using namespace std;

int main () {
int length;
char * buffer;

ifstream is;
is.open (“test.txt”, ios::binary );

// get length of file:
is.seekg (0, ios::end);
length = is.tellg();
is.seekg (0, ios::beg);

// allocate memory:
buffer = new char [length];

// read data as a block:
is.read (buffer,length);

is.close();

cout.write (buffer,length);

return 0;
}

This entry was posted in open-source. Bookmark the permalink.

Leave a comment