push_back
appends individual characters to the string. What you want is to convert a number to a string and then concatenate this string to another string. That’s a fundamentally different operation.
To convert a number to a string, use to_string
. To concatenate strings, you can simply use +
:
std::string prefix = std::string(1, C++);
L.push_back(prefix + std::to_string(i));
If your compiler doesn’t support C++11 yet, there’s the solution using a stringstream
:
std::ostringstream ostr;
ostr << C++ << i;
L.push_back(ostr.str());