std::vector to string with custom delimiter

前端 未结 9 1283
独厮守ぢ
独厮守ぢ 2020-12-03 16:42

I would like to copy the contents of a vector to one long string with a custom delimiter. So far, I\'ve tried:

// .h
string getLabe         


        
9条回答
  •  执笔经年
    2020-12-03 17:08

    Use delimiter.c_str() as the delimiter:

    copy(x.begin(),x.end(), ostream_iterator(s,delimiter.c_str()));
    

    That way, you get a const char* pointing to the string, which is what ostream_operator expects from your std::string.

提交回复
热议问题