To turn a number in ascii in any base in c i would use sprintf. Whats the c++ equivelent?
Printable View
To turn a number in ascii in any base in c i would use sprintf. Whats the c++ equivelent?
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?
yeah it does
itoa(number, string it goes in, base you want);
Thnks parksie but i need to do it into a buffer. Its for a windows app.
Isnt itoa a c function?
works for me in windows programs...thats the only way I've been taught to output numbers in windows
what are the things for the different bases? i tried bin but it didn't work (for binary)Quote:
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?
To get it into a buffer use stringstream (header <sstream>, for <string> objects) or strstream (header <strstream>, for char* C-style strings).
There seems to be no way to choose any base, setbase only accepts 8, 10 and 16 as arguments.Code:stringstream ss;
ss << hex << 100 << oct << 255 << endl;