C++ 31 Jan 2010 23:31:34
Snippet: Convert String to Hex
//tinodidriksen.com/uploads/code/cpp/string-to-hex.cpp
#include <string> #include <sstream> #include <iostream> #include <iomanip> int main() { std::string str("abcABC123\xff\x01"); std::stringstream ss; for (size_t i=0 ; i<str.length() ; ++i) { ss << std::setw(2) << std::setfill('0') << std::hex << (int(str[i])&0xFF); } std::cout << ss.str(); }