• Advertisement
Sign in to follow this  

Resticting vector size

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

I have a vector which can have items added into it at any time, but I want to restrict it's size to 200. So if an object gets past the position of 200 in the vector, then it just gets deleted from the vector. The code I am currently using (which does not seem to be working) is as follows:
if(SMParticles.size() > 200)
{
	for(int i = 0; i < (SMParticles.size() - 200); i++)
		SMParticles.pop_back();

	std::vector<Particle> Temp;
	Temp.assign(SMParticles.begin(), SMParticles.end());
	Temp.swap(SMParticles);
}

Any help on getting this to work is much appreciated, -Chris

Share this post


Link to post
Share on other sites
Advertisement

if(SMParticles.size() > 200)
SMParticles.erase(SMParticles.begin() + 200, SMParticles.end());

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement