可能重复:
如何在C++中将数字转换为字符串,反之亦然
陶氏string在C++中将积分值转换为a ?
这就是我尝试过的:
for(size_t i = 0;vecServiceList.size()>i;i++)
{
if ( ! vecServiceList[i].empty() )
{
string sService = "\t" + i +". "+ vecServiceList[i] ;
}
}
Run Code Online (Sandbox Code Playgroud)
这是错误:
invalid operands of types 'const char*' and 'const char [3]' to binary 'operator+'
Run Code Online (Sandbox Code Playgroud)
dre*_*lax 20
您可以使用字符串流:
#include <sstream>
...
for (size_t i = 0; ... ; ...)
{
std::stringstream ss;
ss << "\t" << i << vecServiceList[i];
std::string sService = ss.str();
// do what you want with sService
}
Run Code Online (Sandbox Code Playgroud)