Comparing std::streampos to 0

M

mathieu

Hi,

Does anyone has a portable way of comparing a streampos to 0 ?

I tried:

if( is.tellg() == 0 ) {}

but this fails on gcc 4.0

and

if( is.tellg() - 0 == 0 ) {}

but this fails with gcc 4.5

ref:

#include <fstream>
int main()
{
std::ifstream is( "bla.txt" );
if( is.tellg() == 0 ) {}
return 0;
}

thanks
 
V

Victor Bazarov

Does anyone has a portable way of comparing a streampos to 0 ?

I tried:

if( is.tellg() == 0 ) {}

but this fails on gcc 4.0

How? What's the error message?
and

if( is.tellg() - 0 == 0 ) {}

but this fails with gcc 4.5

How? What's the error message?
ref:

#include<fstream>
int main()
{
std::ifstream is( "bla.txt" );
if( is.tellg() == 0 ) {}
return 0;
}

The failure with Comeau Online test is that 'std::streampos' has no
conversion to an arithmetic type. Try

if (is.tellg() == std::streampos(0))

That's probably what you want... 'std::streampos' is
implementation-defined class.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top