这是我的代码:
unsigned long a_ptr = *(unsigned long*)agent.m_ptr;
std::string a_type = agTypeToText(agent.GetType());
std::string a_cat = agCategoryToText(agent.GetCategory());
std::stringstream selInfo;
selInfo << "Agent pointer: " << a_ptr << "\nAgent type: " << a_type << "\nAgent category: " << a_cat;
当我显示它时,a_ptr看起来像834,993,193
实际上我希望它显示为十六进制数字,如0xFACEF00D,有或没有0x。有什么方法可以用stringstream做到这一点吗?
答案 0 :(得分:1)
将std::hex
传递到stringstream
std::stringstream ss;
unsigned long v = 12345678910;
ss << std::hex << v;
std::cout << ss.str() << '\n';
或者如果你喜欢大写数字
ss << std::uppercase << std::hex << v;