domlao domlao - 1 year ago 143
C++ Question

Use stream instead of snprintf

I'm not fairly familiar in C++ stream API and I want to convert a C code using stream in C++,

char sHex[20] = {0};
int numid = 2;

snprintf( sHex, sizeof(sHex) - 1, "%X", numId );

Answer Source
stringstream ss;
ss << uppercase << hex << numId;
string res = ss.str();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download