Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Converting 64-bit interger to character

Reply
Thread Tools

Converting 64-bit interger to character

 
 
Tim Slattery
Guest
Posts: n/a
 
      01-05-2007
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: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://www.velocityreviews.com/forums/(E-Mail Removed)
http://members.cox.net/slatteryt
 
Reply With Quote
 
 
 
 
Jim Langston
Guest
Posts: n/a
 
      01-05-2007
"Tim Slattery" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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: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.


 
Reply With Quote
 
 
 
 
Pete C
Guest
Posts: n/a
 
      01-06-2007
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
reverse the bits in an interger? KG C Programming 40 06-21-2007 08:01 PM
How to represent interger powers in C++? heng C++ 3 12-06-2006 03:23 AM
std_logic_vector ==> interger? uvbaz VHDL 6 09-12-2006 08:13 AM
Any easy to printf an interger in 9,999, 99 format? I_have_nothing C Programming 4 05-13-2005 08:55 AM
Cannot be converted to 'Interger' =?Utf-8?B?VGltOjouLg==?= ASP .Net 2 11-03-2004 02:32 PM



Advertisments