Advertisement Jump to content
Sign in to follow this  

Is this is good idea? STL.

This topic is 4892 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!