Converting 64-bit interger to character

T

Tim Slattery

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
(e-mail address removed)
http://members.cox.net/slatteryt
 
J

Jim Langston

Tim Slattery said:
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.
 
P

Pete C

Tim said:
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.
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top