0

here's my code:

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;

when I display this, a_ptr looks like 834,993,193

when in reality i want it to display as a hexadecimal number, something like 0xFACEF00D, with or without the 0x. is there any way I can do this with stringstream?

Stephen K
  • 697
  • 9
  • 26

1 Answers1

1

Yes by passing std::hex to your stringstream

std::stringstream ss;
unsigned long v = 12345678910;
ss << std::hex << v;
std::cout << ss.str() << '\n';

or if you prefer uppercase digits

ss << std::uppercase << std::hex << v;
Ryan Haining
  • 35,360
  • 15
  • 114
  • 174