问题
Say, we get int A 333; int B 4444 and int C 5454 we want to concatenate them into one unsigned long long 000333 004444 005454 00 (with format like 0/1 int sign, int). How to do such formating in C++, and are there any C++11 tools that can simplify process?
回答1:
You could make strings from the ints using std::to_string, concatenate as necessary, then convert to long long using std::stoll.
回答2:
Do you just mean this?
unsigned int A = 333;
unsigned int B = 4444;
unsigned int C = 5454;
unsigned long long r = A*100000000000000ULL + B*100000000ULL + C*100ULL;
Proof it works: http://ideone.com/XWFdU
来源:https://stackoverflow.com/questions/11187898/how-to-concatinate-3-ints-into-unsigned-long-long