By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,332 Members | 1,414 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,332 IT Pros & Developers. It's quick & easy.

Casting, inserter and streamspos?

P: n/a
somewhere in MyClass
....
std::streampos pos;
long long Id;
char* Key;
......
std::istream& jme::operator>>( 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::operator>>(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

Dec 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Al-Burak wrote:
somewhere in MyClass
....
std::streampos pos;
long long Id;
char* Key;
......
std::istream& jme::operator>>( 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::operator>>(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

Dec 21 '05 #2

P: n/a
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

Dec 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.