0
How to concatenate two numbers in c ++
1+2=12
4 Respuestas
+ 1
int main() {
int x=1,y=2;
cout<<x<<""<<y;
return 0;
}
+ 2
Two ways
1) Convert integers to characters and combine them in a string.
2) Multiply first number with 10 and then add second number to the previous result.
1 * 10 = 10 + 2 = 12
+ 2
Please also specify the language in Relevant Tags for scope clarity. You can write the example 67 + 76 = 6776 in Description section 👍
+ 1
If You want to convert both a and b to strings, concatenate them, then convert the result back to an integer. Here's an example using string streams:
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main()
{
int a = 4;
int b = 5;
ostringstream oss;
oss << a << b;
istringstream iss(oss.str());
int c;
iss >> c;
cout << c << endl;
}