If you want an int
as result, multiply with the base:
int a = 5;
int b = 5;
int c = 10 * a + b; // 55
If you want the result to be a std::string
, use std::to_string
(since C++11):
int a = 5;
int b = 5;
std::string c = std::to_string(a) + std::to_string(b); // "55"
Before C++11, you can use a std::stringstream
:
int a = 5;
int b = 5;
std::stringstream ss;
ss << a << b;
std::string c = ss.str(); // "55"
3
solved How to add a number to an integer like a string