Casting, inserter and streamspos?

A

Al-Burak

somewhere in MyClass
....
std::streampos pos;
long long Id;
char* Key;
......
std::istream& jme::eek:perator>>( std::istream& is, jme::MyClass& obj ) {
is >> obj.Id;
is.ignore(1);
is >> obj.Key;
is.ignore(1);
is >> static_cast<double>(obj.pos); // << Error
return is;
}
When I try 'is >> obj.pos', the compiler complains saying that it is an
umbiguous overload for operator>>, but if I try to 'type cast' the
value to double, the compiler complains saying:
file.cpp: In function `std::istream& jme::eek:perator>>(std::istream&,
jme::MyClass&)':
file.cpp:34: error: no match for 'operator>>' in 'is >> #`float_expr'
not supported by dump_expr#<expression error>'
What am I doing wrong?
What can I do to get my program to work?


TIA
 
M

mlimber

Al-Burak said:
somewhere in MyClass
....
std::streampos pos;
long long Id;
char* Key;
......
std::istream& jme::eek:perator>>( std::istream& is, jme::MyClass& obj ) {
is >> obj.Id;
is.ignore(1);
is >> obj.Key;
is.ignore(1);
is >> static_cast<double>(obj.pos); // << Error
return is;
}
When I try 'is >> obj.pos', the compiler complains saying that it is an
umbiguous overload for operator>>, but if I try to 'type cast' the
value to double, the compiler complains saying:
file.cpp: In function `std::istream& jme::eek:perator>>(std::istream&,
jme::MyClass&)':
file.cpp:34: error: no match for 'operator>>' in 'is >> #`float_expr'
not supported by dump_expr#<expression error>'
What am I doing wrong?
What can I do to get my program to work?


TIA

See this link:

http://www.cplusplus.com/ref/iostream/streampos.html

You could add an istream extractor for std::streampos (none exists in
the standard library), or you can read in an int, and initialize pos
with it:

int i;
is >> i;
obj.pos = streampos( i );

Cheers! --M
 
A

Al-Burak

Thanks 'mlimber'.
I hope not to be too annoying with all this questions, but if
std::streampos is supposed to store the value of an arbitrary position
with in a file, what would happen if the file grows bigger than
INT_MAX, as they tend to do, and the value of the integral type gets
rolled over to zero?

Thanks in advance
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top