concatenating vectors

M

mike7411

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.
 
V

Victor Bazarov

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
 
B

BobR

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<int> Vdata1(5, 5);
std::vector<int> Vdata2(10, 10);
std::copy( Vdata2.begin(), Vdata2.end(),
std::back_inserter( Vdata1 ) );

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

Gianni Mariani

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,055
Members
47,659
Latest member
salragu

Latest Threads

Top