This is the definition of the function basic_istream::tellg() in VS2010. Note that the function returns a variable of type pos_type. However when I replace the type streamoffused in the example, given below, by pos_type, the compiler complains (C2065: ‘pos_type’ : undeclared identifier).
pos_type is defined in <fstream> as typedef typename _Traits::pos_type pos_type;.
// basic_istream_tellg.cpp
// compile with: /EHsc
#include <iostream>
#include <fstream>
int main()
{
using namespace std;
ifstream file;
char c;
streamoff i; // compiler complains if I replace streamoff by pos_type
file.open("basic_istream_tellg.txt");
i = file.tellg();
file >> c;
cout << c << " " << i << endl;
i = file.tellg();
file >> c;
cout << c << " " << i << endl;
}
You cannot just write
pos_typewithout qualification. Note that it is a member ofifstream. So you’ve to write this:That should work now.
Also, since
using namespace std;is considered bad, you should avoid it, and instead should prefer using full qualification as:In C++11, you can use
autoinstead.and let the compiler deduce
ito bestd::ifstream::pos_type.Hope that helps.