How to concatenate values of different types in a string?

1

How do I concatenate all this string within a variable? Is there a more elegant way to solve my problem?

int num1 = 1;
int num2 = 2;
int num3 = 3;
char simbol1 = '+';
char simbol2 = '-'; 

string equation = num1 + " " + simbol1 + " ( " + num3 + " " + simbol2 + " " + num3 + " ) = ? ";
    
asked by anonymous 26.09.2018 / 21:05

1 answer

2

I imagine this is what you want:

auto equation = to_string(num1) + " " + simbol1 + " ( " + to_string(num2) + " " + simbol2 + " " + to_string(num2) + " ) = ? ";

You need to convert the number to string before concatenating.

    
26.09.2018 / 21:24