By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,197 Members | 1,207 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,197 IT Pros & Developers. It's quick & easy.

concatenating vectors

P: n/a
I was just wondering if there is a built-in function for concatenating
two STL vector objects. For instance, I might have a vector with 10
objects and one with 20. Then, I would call this built-in function
to concatenate the vectors into a vector with 30 objects.

Any help is appreciated. Thank you.

Aug 10 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
mi******@gmail.com wrote:
I was just wondering if there is a built-in function for concatenating
two STL vector objects. For instance, I might have a vector with 10
objects and one with 20. Then, I would call this built-in function
to concatenate the vectors into a vector with 30 objects.
RTFM about the 'insert' member of 'std::vector'. You need the one
with three iterator arguments. Basically you need to insert the
second vector right before the end of the first one (hint, hint...)

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 10 '07 #2

P: n/a

<mi******@gmail.comwrote in message...
I was just wondering if there is a built-in function for concatenating
two STL vector objects. For instance, I might have a vector with 10
objects and one with 20. Then, I would call this built-in function
to concatenate the vectors into a vector with 30 objects.

Any help is appreciated. Thank you.
What Victor said. Or use std::copy:

std::vector<intVdata1(5, 5);
std::vector<intVdata2(10, 10);
std::copy( Vdata2.begin(), Vdata2.end(),
std::back_inserter( Vdata1 ) );

std::copy( Vdata1.begin(), Vdata1.end(),
std::ostream_iterator<int>( cout, "\n" ) );

--
Bob R
POVrookie
Aug 10 '07 #3

P: n/a
mi******@gmail.com wrote:
I was just wondering if there is a built-in function for concatenating
two STL vector objects. For instance, I might have a vector with 10
objects and one with 20. Then, I would call this built-in function
to concatenate the vectors into a vector with 30 objects.

Any help is appreciated. Thank you.
std::vector::append.
Aug 10 '07 #4

P: n/a
Gianni Mariani wrote:
mi******@gmail.com wrote:
>I was just wondering if there is a built-in function for
concatenating two STL vector objects. For instance, I might have a
vector with 10 objects and one with 20. Then, I would call this
built-in function to concatenate the vectors into a vector with 30
objects. Any help is appreciated. Thank you.

std::vector::append.
Your library provides *that*? Wow! Are you sure you're not confusing
'std::vector' with 'std::string'?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 10 '07 #5

P: n/a
Victor Bazarov wrote:
Gianni Mariani wrote:
>mi******@gmail.com wrote:
>>I was just wondering if there is a built-in function for
concatenating two STL vector objects. For instance, I might have a
vector with 10 objects and one with 20. Then, I would call this
built-in function to concatenate the vectors into a vector with 30
objects. Any help is appreciated. Thank you.
std::vector::append.

Your library provides *that*? Wow! Are you sure you're not confusing
'std::vector' with 'std::string'?
Oops -

std::vector::insert ...
Aug 10 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.