0

How to concatenate two numbers in c ++

1+2=12

23rd Oct 2019, 3:20 PM
Mayank Kumar Singh
Mayank  Kumar Singh - avatar
4 Respuestas
+ 1
int main() { int x=1,y=2; cout<<x<<""<<y; return 0; }
23rd Oct 2019, 3:37 PM
Chirag Kumar
Chirag Kumar - avatar
+ 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
23rd Oct 2019, 4:09 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 2
Please also specify the language in Relevant Tags for scope clarity. You can write the example 67 + 76 = 6776 in Description section 👍
23rd Oct 2019, 4:09 PM
Ipang
+ 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; }
3rd Sep 2020, 5:22 AM
Harsh Vardhan Singh
Harsh Vardhan Singh - avatar