Convert Int to String in C ++

0

How do I make the String resultado receive the int value of cont3 and the char value of c[cont] ?

resultado=" ";
resultado=resultado+to_string(**cont3**)+to_string(**c[cont1**]);

I tried to use to_string() but it did not solve my problem.

    
asked by anonymous 03.05.2018 / 12:55

1 answer

2

You can do it this way:

#include <iostream>
#include <string>

int main()
{
  std::string resultado = " ";
  int n = 1;
  char l = 'a';

  resultado = resultado + std::to_string(n) + l;

  std::cout << resultado;
}

Result is already a string, n is of type int so it is converted with std::to_string and l is char and can be concatenated direct.

resultado = resultado + std::to_string(n) + l;

Outcome

  

This code is for C ++ 11

    
03.05.2018 / 13:39