How to use to_string function

I am creating a function that takes two integers and adds them returning as the string "a + b = c". I have to use the to_string function and it only seems to return the answer not the full equation.

Here is my code:
string additionToString(int a, int b)
{
string additions = inToString(a + b);
return addition;
}

Thanks!
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <string>

std::string addition( int a, int b ) // assumes that a+b is within the range of int
{ return std::to_string(a) + " + " + std::to_string(b) + " == " + std::to_string(a+b) ; }

int main()
{
   for( int a : { 5, -23, 78, 0 } )
       for( int b : { 17, 66, 1, -7 } )
           std::cout << addition(a,b) << '\n' << addition(b,a) << '\n' ;
}

http://coliru.stacked-crooked.com/a/5ecb571e6a9f1d6c
Topic archived. No new replies allowed.