size_t convert/cast to string in C++

c++, string

Solution

You could use a string stream:

#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
}

Problem

Possible Duplicate: How to convert a number to string and vice versa in C++ How do I convert an integral value to a `string` in C++? This is what I've tried: ``` for(size_t i = 0;vecServiceList.size()>i;i++) { if ( ! vecServiceList[i].empty() ) { string sService = "\t" + i +". "+ vecServiceList[i] ; } } ``` And here is the error: ``` invalid operands of types 'const char*' and 'const char [3]' to binary 'operator+' ```

Original source

Related problems