tags:

views:

223

answers:

1

Using standard C++ I/O (such as std::cout), is it possible to "print" the value of an array (however long) into a string?

For example, say I have the following array:

unsigned long C = {0x497fecf2, 0xfa989ea3, 0xd594974e};

I'd like to be able to print those values into a string, and then remove the "0x" from them. From another SO question, I've found how to print hex values with cout.

Is what I'm asking possible the way I've described?

Would it be better to just go back to an old comp sci assignment for base conversions, and convert the decimal value into hex, using a lookup table to add the appropriate next hexit to the string?

+3  A: 

Create a std::ostringstream, and print them to it just like you could to cout. Retrieve the string with the contents with the stringstream's str() member.

Jerry Coffin
I knew it couldn't be that hard - just didn't know where to look. Thanks
warren