Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C - C++ Learning > Re: concatenate...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 3 Topic 4111 of 4262
Post > Topic >>

Re: concatenate vector of strings

by dasjotre <dasjotre@[EMAIL PROTECTED] > Apr 14, 2008 at 05:08 AM

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
 




 3 Posts in Topic:
concatenate vector of strings
utab <umut.tabak@[EMAI  2008-04-13 12:40:44 
Re: concatenate vector of strings
Jerry Coffin <jcoffin@  2008-04-13 14:10:37 
Re: concatenate vector of strings
dasjotre <dasjotre@[EM  2008-04-14 05:08:32 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Sep 6 13:39:11 CDT 2008.