I want to concatenate two integers, that is not adding their values, but join them.
For example:
int a=2,b;
cin>>b;
a=a+3;
a should be something like 23 instead of 5.
How can I do that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A simple method would be to multiply the number by 10 and then add the new integer.
Edit: Other answers were more accurate. In the case where a number can be above 10 you will need to either treat them as strings and then convert back to int (itoa on the c_str()). If you want to keep them as int, you will need to know which power of 10 contains your new value and multiply the number by this power of 10 to make enough room for the new number.