is there an easy way to convert an ASCII std::string to HEX? I don\'t want to convert it to a number, I only want to convert each ASCII character to it\'s HEX value. The out
If you don't care about the 0x it's easy to do using std::copy
:
#include
#include
#include
#include
#include
namespace {
const std::string test="hello world";
}
int main() {
std::ostringstream result;
result << std::setw(2) << std::setfill('0') << std::hex << std::uppercase;
std::copy(test.begin(), test.end(), std::ostream_iterator(result, " "));
std::cout << test << ":" << result.str() << std::endl;
}