8

重複の可能性:
C++ で数値を文字列に、またはその逆に変換する方法

stringC++ で整数値を a に変換するにはどうすればよいですか?

これは私が試したことです:

for(size_t i = 0;vecServiceList.size()>i;i++)
{
    if ( ! vecServiceList[i].empty() )
    {
        string sService = "\t" + i +". "+  vecServiceList[i] ;
    }
}

そして、ここにエラーがあります:

invalid operands of types 'const char*' and 'const char [3]' to binary 'operator+'
4

1 に答える 1

21

文字列ストリームを使用できます。

#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
}
于 2012-05-09T05:07:27.787 に答える