+ 2
c++ how i can combine int and string ?
how can i combine string and int for example int x = 30; string name ="john"; string result = name + x; cout <<result<<endl;
1 Antwort
+ 12
Erm, guys.
No operator "+" matches std::string + int. You have to explicitly convert int to string and then concatenate it using +.
#include <iostream>
#include <sstream>
#include <string>
int main()
{
std::stringstream obj;
std::string test = "test";
int integer = 39;
obj << integer;
std::string test2 = test + obj.str();
std::cout << test2;
return 0;
}