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?
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.
精彩评论