On Apr 13, 8:40 pm, utab <umut.ta...@[EMAIL PROTECTED]
> wrote:
> Dear all,
>
> I tried to concatenate a vector<string> into one string by using copy
> algorithm however my code did not even compile. However I could not
> understand why I can not even compile it.
>
> Say,
>
> string str("C++ ");
> vector<string> strings(10, str);
> string s;
> copy(strings.begin(),strings.end(),back_inserter(s));
>
> back_inserter can be used on a string because it is ok to use
> push_back on string class. To use back_inserter, the container should
> sup****t push_back and strings are also containers with push_back
> member function, right?
>
> But I get compile errors. I accomplished that later with ac***ulate
> however but wondered the reason of the above problem.
>
> Rgds,
you can use stringstream to ac***ulate the result
std::vector<std::string> string_vector_;
std::stringstream ss;
std::copy(string_vector_.begin(), string_vector_.end(),
std::ostream_iterator<std::string>(ss));
std::string result = ss.str();
DS


|