我正在执行以下代码,已阅读此内容:
#include <iostream>
#include <boost/format.hpp>
#include <boost/algorithm/string.hpp>
struct CharacterEscaper
{
template<typename FindResultT>
std::string operator()(const FindResultT& Match) const
{
std::string s;
for (typename FindResultT::const_iterator i = Match.begin();i != Match.end();i++)
{
s += str(boost::format("\\x%02x") % static_cast<int>(*i));
}
return s;
}
};
int main (int argc, char **argv)
{
std::string s("start\x0aend");
boost::find_format_all(s, boost::token_finder(!boost::is_print()), CharacterEscaper());
std::cout << s << std::endl;
return 0;
}
我得到的输出是这样的:
start\xffffffaend
我期待以下内容:
start\x0aend
读过这个:
http://en.cppreference.com/w/cpp/language/escape
什么是正确的?