Sign in to follow this  

Is this is good idea? STL.

Recommended Posts

Would this work.. vector<int> Vec1; vector<int> Vec2; Assign various values into Vec1 here.. Vec2 = Vec1. Would this copy all the elements for me, or do I have to loop through and do it manually? Mark

Share this post

Link to post
Share on other sites
How can I copy thee? Let me count the ways:
std::vector< int > vector1;
std::vector< int > vector2;

// copy assignment operator
vector2 = vector1;

// assign member function
vector2.assign(vector1.begin(), vector1.end());

// insert member function
vector2.insert(vector2.end(), vector1.begin(), vector1.end());

// std::copy
std::copy(vector1.begin(), vector1.end(), std::back_inserter(vector2));


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this