Command for combining integers. C ++

2

Is there a command that allows combining two integers?

I have a variable that is worth 5 and one that is 6 For example, is there any command that allows you to play the combination of these variables, the value 56 , in a third variable?     

asked by anonymous 27.07.2016 / 22:20

2 answers

2

Here's another alternative using Stringstream :

#include <iostream>
#include <sstream>

using namespace std;

int main() {
    int num1, num2, num3;
    stringstream ss;

    num1 = 505;
    num2 = 560;

    ss << num1 << num2;
    ss >> num3;

    cout << num3 << endl;
    return 0;
}

View demonstração

    
27.07.2016 / 23:26
3

The short answer is:

unsigned concatenate(unsigned x, unsigned y) {
    unsigned pow = 10;
    while(y >= pow)
        pow *= 10;
   return x * pow + y;        
}

All credit for: Response in English

    
27.07.2016 / 22:26