|
-
Mar 8th, 2002, 11:47 PM
#1
Converting Bases in c++
To turn a number in ascii in any base in c i would use sprintf. Whats the c++ equivelent?
-
Mar 9th, 2002, 06:04 AM
#2
Monday Morning Lunatic
Is this the sort of thing you mean:
Code:
cout << hex << 100 << oct << 255 << endl;
?
Or did you want something for any random base? Doesn't itoa have a radix argument?
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Mar 9th, 2002, 10:25 AM
#3
Frenzied Member
yeah it does
itoa(number, string it goes in, base you want);
-
Mar 9th, 2002, 12:26 PM
#4
Thnks parksie but i need to do it into a buffer. Its for a windows app.
Isnt itoa a c function?
-
Mar 9th, 2002, 06:41 PM
#5
Frenzied Member
works for me in windows programs...thats the only way I've been taught to output numbers in windows
-
Mar 9th, 2002, 08:12 PM
#6
PowerPoster
Originally posted by parksie
Is this the sort of thing you mean:
Code:
cout << hex << 100 << oct << 255 << endl;
?
Or did you want something for any random base? Doesn't itoa have a radix argument?
what are the things for the different bases? i tried bin but it didn't work (for binary)
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
-
Mar 10th, 2002, 07:40 AM
#7
To get it into a buffer use stringstream (header <sstream>, for <string> objects) or strstream (header <strstream>, for char* C-style strings).
Code:
stringstream ss;
ss << hex << 100 << oct << 255 << endl;
There seems to be no way to choose any base, setbase only accepts 8, 10 and 16 as arguments.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|