The easiest way to turn numbers into a string is to use ostringstream
#include <sstream> #include <string> std::ostringstream os; os << x << y << z; std::string str = os.str(); // 6490240
You can even use the manipulators for this in hexadecimal or octal:
os << std::hex << x << y << z;
Update
Since you clarified what you really want to do, I updated my answer. You want to take the RGB values ββas three bytes and somehow use them as a key. This would be best done using long int, rather than as strings. You can still simplify int ints to print on the screen.
unsigned long rgb = 0; byte* b = reinterpret_cast<byte*>(&rgb); b[0] = x; b[1] = y; b[2] = z;
Then you can use long int rgb as your key, very efficiently. Whenever you want to print it, you can still do it:
std::cout << std::hex << rgb;
Depending on the finiteness of your system, you may need to reproduce which bytes of the long int you specify. My example overwrites bytes 0-2, but you can write bytes 1-3. And you can write the order as z, y, x instead of x, y, z. Such details are platform dependent. Although if you never want to print the RGB value, but just want to consider it a hash, you do not need to worry about what bytes you write or in which order.
source share