Casting, inserter and streamspos?

Discussion in 'C++' started by Al-Burak, Dec 21, 2005.

  1. Al-Burak

    Al-Burak Guest

    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
     
    Al-Burak, Dec 21, 2005
    #1
    1. Advertising

  2. Al-Burak

    mlimber Guest

    Al-Burak wrote:
    > 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
     
    mlimber, Dec 21, 2005
    #2
    1. Advertising

  3. Al-Burak

    Al-Burak Guest

    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
     
    Al-Burak, Dec 21, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. kevin
    Replies:
    11
    Views:
    5,811
    Andrew McDonagh
    Jan 8, 2005
  2. nimrod
    Replies:
    1
    Views:
    385
    Buster Copley
    Aug 4, 2003
  3. Randy
    Replies:
    23
    Views:
    841
  4. laikon
    Replies:
    3
    Views:
    351
    James Kanze
    Oct 8, 2008
  5. Sosuke

    Up casting and down casting

    Sosuke, Dec 20, 2009, in forum: C++
    Replies:
    2
    Views:
    569
    James Kanze
    Dec 20, 2009
Loading...

Share This Page