<分区>
我有一个接受const char*
参数的函数。我需要连接两个字符串文字和一个 int
以传递给这个参数。基本上这就是我想要做的:
open(const char* filename) {}
void loadFile(int fileID)
{
open("file" + fileID + ".xml");
}
int main()
{
loadFile(1);
return 0;
}
我怎样才能使这项工作尽可能简单?我尝试更改 loadFile 函数以采用 const char*
然后执行 open(std::string("file").c_str() + fileID + std::string(". xml").c_str());
但随后我得到了 错误:无效的操作数类型 'const char*' 和 'const char*' 到二进制 'operator+'
所以我迷路了。