是否可以格式化std::string
传递一组参数?
目前我正在以这种方式格式化字符串:
string helloString = "Hello %s and %s";
vector<string> tokens; //initialized vector of strings
const char* helloStringArr = helloString.c_str();
char output[1000];
sprintf_s(output, 1000, helloStringArr, tokens.at(0).c_str(), tokens.at(1).c_str());
但是向量的大小是在运行时确定的。是否有任何类似的函数sprintf_s
接受参数集合并格式化 std::string/char*?我的开发环境是 MS Visual C++ 2010 Express。
编辑: 我想实现类似的东西:
sprintf_s(output, 1000, helloStringArr, tokens);