sspp sspp - 7 months ago 47
C++ Question

How can I concatenate string + int + string in C++?

How can I concatenate i + name + letter + i?

for(int i = 0; i < 10; ++i){

//I need a const char* to pass as a parameter to another function
const char* name = "mki";

//The letter is equal to "A" for the first 2, "B" for the second 3,
//"C" for the following 4 ...
const char* final_string = ???

I already tried using:


But I got an error saying that

to_string is undefined for std

I'm using Visual C++.


You have an older version of VC++ that does not support the current C++ standard. In that case, you have to do it the old-fashioned way.

#include <sstream>

std::ostringstream o;

o << "mki" << i << "abc";

std::string s=o.str();