5
How to proceed to add an element at the position I specify in a std::vector
? Not to delete what you already have, but to add in the middle. Here’s an example:
Let’s assume that inside a std::vector
possess the elements
{1,2,3,4,5,6,7,8,9};
And I want to add a number before 4 and after 3, but without deleting any element, so:
{1,2,3,10,4,5,6,7,8,9}
How to proceed? Is this possible? Or do I need to use some other container, like the list
?
Well, is there any other faster way to do this? Here in my program gave a lag... Obg
– Thiago Henrique Hupner
I doubt it exists, but it is not to be too slow no. I do not know how you are using, so I can not say if it is right. But if there really is a performance problem, then you have to use another data structure that allows you to enter more quickly, giving up some feature that the
vector
has, for example,list
.– Maniero