tommym121
asked on
using std::stringstream to print a string in hex decimal form
I am using a log4cpp to log any debug info to a file.
log4cpp::Category::getRoot () << log4cpp::Priority::DEBUG << "My error string";
There is time I would like to turn the error string into an array of hex codes for each character in the string
log4cpp::Category::getRoot () << log4cpp::Priority::DEBUG << "0x65 0x63 0x67 0x68 .. .. ..";
What is the best way to transform "My error string" to "0x65 0x63 0x67 0x68 .. .. .."
log4cpp::Category::getRoot
There is time I would like to turn the error string into an array of hex codes for each character in the string
log4cpp::Category::getRoot
What is the best way to transform "My error string" to "0x65 0x63 0x67 0x68 .. .. .."
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
JKR,
I forget to mention if what I am trying to print out is an array of char (e.g. TCP/IP) packet, '\n' can be present in the char array, I would like to print '\n' as ASCII code and still able to print 16 maximum HEX number in a row.
So I suppose I can not use string or stringstream am I right
I forget to mention if what I am trying to print out is an array of char (e.g. TCP/IP) packet, '\n' can be present in the char array, I would like to print '\n' as ASCII code and still able to print 16 maximum HEX number in a row.
So I suppose I can not use string or stringstream am I right
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
ASKER
I really like your new trick, as I am learning to apply generic programming. (template).
One more winkle I like to add, what if I would like to print max16 Hex numbers in a row.
how would I do it.