Just a small code fragment to help you through the night:
#include <iostream>
#include <sstream>
#include <string>
#include <boost/foreach.hpp>
std::string repr(const std::string& s)
{
std::ostringstream ss;
BOOST_FOREACH(const char c, s) {
if ((signed char)c < 32) {
ss << "\\x" << std::hex << std::right;
ss.width(2); ss.fill('0');
ss << (int)(unsigned char)c;
} else {
ss << c;
}
}
return ss.str();
}
int main()
{
std::cout << repr("as\td\xfe\x20\x1f") << std::endl;
}
jbook2:~ spaans$ make repr
g++ repr.cc -o repr
jbook2:~ spaans$ ./repr
as\x09d\xfe \x1f
jbook2:~ spaans$ # \o/