Converting 64-bit interger to character

Discussion in 'C++' started by Tim Slattery, Jan 5, 2007.

  1. Tim Slattery

    Tim Slattery Guest

    I'm trying to convert a 64-bit inter to a character string, and
    failing. I don't understand the error.

    here's the code:

    __int64 num = 123456789012;
    std::eek:stringstream buffer;
    buffer << num;

    std::string formatted = buffer.str();

    The error message points at the third line and says: operator << is
    ambiguous. Huh??

    --
    Tim Slattery

    http://members.cox.net/slatteryt
    Tim Slattery, Jan 5, 2007
    #1
    1. Advertising

  2. Tim Slattery

    Jim Langston Guest

    "Tim Slattery" <> wrote in message
    news:...
    > I'm trying to convert a 64-bit inter to a character string, and
    > failing. I don't understand the error.
    >
    > here's the code:
    >
    > __int64 num = 123456789012;
    > std::eek:stringstream buffer;
    > buffer << num;
    >
    > std::string formatted = buffer.str();
    >
    > The error message points at the third line and says: operator << is
    > ambiguous. Huh??


    Apparently your compiler doesn't define an operator<< for an ostringstream
    for 16 bit unsigned ints.

    However, your compiler usually tells you the choices it has after the error
    message (along the lines of, operator<<( ostringbuffer, int ) or
    operator<<( ostringbuffer, unsigned int ), etc...

    Go through those choices and see if you have anything that's 64 bit. You
    might be lucky and maybe they have 64 bit unsigned ints, in that case either
    change it to unsigned 64 bit int or cast it in the << statment.
    Jim Langston, Jan 5, 2007
    #2
    1. Advertising

  3. Tim Slattery

    Pete C Guest

    Tim Slattery wrote:
    > I'm trying to convert a 64-bit inter to a character string, and
    > failing. I don't understand the error.
    >
    > here's the code:
    >
    > __int64 num = 123456789012;


    In addition to what Jim said above, 123456789012 as you have written it
    is an int literal, yet too large to fit in a (32-bit) int. So you may
    get a warning and/or unexpected results. gcc would let you write
    123456789012LL to indicate a 64-bit literal. MSVC might let you use the
    same syntax, or there might be something similar - I forget.
    Pete C, Jan 6, 2007
    #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. =?Utf-8?B?VGltOjouLg==?=

    Cannot be converted to 'Interger'

    =?Utf-8?B?VGltOjouLg==?=, Nov 3, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    1,645
    chanmmn
    Nov 3, 2004
  2. uvbaz
    Replies:
    6
    Views:
    7,476
    uvbaz
    Sep 12, 2006
  3. I_have_nothing

    Any easy to printf an interger in 9,999, 99 format?

    I_have_nothing, May 13, 2005, in forum: C Programming
    Replies:
    4
    Views:
    390
    Chris McDonald
    May 13, 2005
  4. Brand Bogard

    8 bit character string to 16 bit character string

    Brand Bogard, May 25, 2006, in forum: C Programming
    Replies:
    8
    Views:
    716
    those who know me have no need of my name
    May 28, 2006
  5. heng
    Replies:
    3
    Views:
    324
    Steven T. Hatton
    Dec 6, 2006
Loading...

Share This Page