C++ tellg() return type
Q What is the return type of tellg()?
A The return type of istream::tellg()
is streampos
. Check out std::istream::tellg.
Q How can I compare tellg() with the unsigned long long int?
A The return value of tellg()
is an integral type. So you can use the usual operators to compare two int
s. However, you are not supposed to do that to draw any conclusions from them. The only operations that the standard claims to support are:
Two objects of this type can be compared with operators == and !=. They can also be subtracted, which yields a value of type streamoff.
Check out std::streampos.
Q Is it possible that the return type of tellg() has a maximum value (from numeric_limits) that is smaller than an unsigned long long int?
A The standard does not make any claims to support it or refute it. It might be true in one platform while false in another.
Additional Info
Comparing streampos
, examples of supported and unsupported compare operations
ifstream if(myinputfile);
// Do stuff.
streampos pos1 = if.tellg();
// Do more stuff
streampos pos2 = if.tellg();
if ( pos1 == pos2 ) // Supported
{
// Do some more stuff.
}
if ( pos1 != pos2 ) // Supported
{
// Do some more stuff.
}
if ( pos1 != pos2 ) // Supported
{
// Do some more stuff.
}
if ( pos1 == 0 ) // supported
{
// Do some more stuff.
}
if ( pos1 != 0) // supported
{
// Do some more stuff.
}
if ( pos1 <= pos2 ) // NOT supported
{
// Do some more stuff.
}
int k = 1200;
if ( k == pos1 ) // NOT supported
{
}