sspp sspp - 1 year ago 56
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";
//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 VC++.

Answer Source

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();