Get and Put File Position Indicators





This video tutorial explains what is the use of get and put position indicators available in c++, how to get/check the get and put position indicators using tellg() and tellp() function, how to set the get and put position indicators using seekg() and seekp() function in detail with example.

source code for this tutorial

#include <iostream>
#include <fstream>
using namespace std;

int main()
{
fstream file("anil.txt",ios::out|ios::in);
if(!file.is_open()){
    cout << "error";
}else{

cout <<file.tellg()<<endl;
cout <<file.tellp()<<endl;
file.seekp(2);
cout <<file.tellg()<<endl;
cout <<file.tellp()<<endl;
}
    return 0;
}