How to convert an integer to a hexadecimal string in C++
int number = 42;
stringstream ss;
ss << hex << number;
// now ss.str(), which is a string, contains "2a"
int number = 42;
stringstream ss;
ss << hex << number;
// now ss.str(), which is a string, contains "2a"
Let me show a nice C/C++ trick I just found out:
Instead of writing:
if (function1())
function2();
you could write:
function1() && function2();
because the right side of the && operator is only evaluated (in this case: called), when function1() is true (returns a non-null value).
Subsequently, instead of:
if (!function1()) // or if (function1()==0) etc.
function2();
you could write:
function1() || function2();
Cool, eh?