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 *をフォーマットするのと同様の関数はありますか?私の開発環境はMSVisualC ++2010Expressです。
編集: 私は似たようなことを達成したいと思います:
sprintf_s(output, 1000, helloStringArr, tokens);