Size_t convert / cast to string in C ++

Possible duplicate:
How to convert a number to a string and vice versa in C ++

Dow convert integral value to string in C ++?

Here is what I 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+' 
+6
source share
1 answer

You can use a stream of lines:

 #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 } 
+15
source

Source: https://habr.com/ru/post/915253/


All Articles