如何连接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 = ???
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试过使用:
std::to_string(i)
Run Code Online (Sandbox Code Playgroud)
但我说错了
对于std,to_string未定义
我正在使用Visual C++.
您有较旧版本的VC++,它不支持当前的C++标准.在这种情况下,你必须以老式的方式做到这一点.
#include <sstream>
std::ostringstream o;
o << "mki" << i << "abc";
std::string s=o.str();
Run Code Online (Sandbox Code Playgroud)