domlao
domlao

Reputation: 16029

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 );

Upvotes: 2

Views: 351

Answers (2)

dreamcrash
dreamcrash

Reputation: 51483

Take a look at Understanding C++ Streams and Stream Buffers it may help you, like as helped me.

Upvotes: 1

Ivan Vergiliev
Ivan Vergiliev

Reputation: 3841

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

Upvotes: 5

Related Questions