Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

kuphryn

Copying *Specific* Elements From VectorA to VectorB :: C++

This topic is 6098 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

Hi. Let say there are two vectors, vectorA and vectorB. ----------------------------------------------------- string dataTemp; std::vector vectorA, vectorB; for (int = 0; i < 10; ++i) { dataTemp += i; vectorA.push_back(dataTemp); } /* The loop above should produce vectorA to look something like this: 0 1 12 123 1234 12345 123456 1234566 12345678 123456789 */ Okay, vectorB is empty. I want to copy *specific* elements from vectorA to vectorB. For example: vectorB.push_back(vectorA[4]); // Is that right? vecotrB.push_back(vectorA[8]); Thanks, Kuphryn

Share this post


Link to post
Share on other sites
Advertisement
No, vectorA will contain:

"" (an empty string)
"1"
"12"
...
"123456789".

But yes, to copy specific elements, you do it exactly the way you said. It''s just like an array. Why didn''t you just try it and see? (I said this in your other thread, too. Also, please delete your double posts - thanks.)

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]

Share this post


Link to post
Share on other sites
I tried it my way, but it did not come out right. vectorB was empty after that algorithm I used.

I used copy to output the data from vectorB to cout, but got a blank screen.

Kuphryn

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!