domlao domlao - 1 month ago 8x
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 );

stringstream ss;
ss << uppercase << hex << numId;
string res = ss.str();