如何在C++中连接字符串+ int +字符串?
问题描述:
如何连接i +名+字母+ i?如何在C++中连接字符串+ int +字符串?
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 = ???
}
我已经尝试使用:
std::to_string(i)
但我得到一个错误,指出
to_string未定义性病
我使用Visual C++。
答
您有VC++不支持当前的C++标准的旧版本。在那种情况下,你必须以老式的方式来做。
#include <sstream>
std::ostringstream o;
o << "mki" << i << "abc";
std::string s=o.str();
使用'的std :: stringstream' – Ari0nhh
检查[这个答案](http://stackoverflow.com/questions/5590381/easiest-way-to-convert-int-to-string-in-c/ 5590404#5590404)关于相关(不重复)的问题。 Sam的答案的宏观版本。 – DevSolar