First remember to give a include
#include <vector>
2- create your vector
std::vector <int> nomeDoVector;
(answering the first question, you can create vector of other things just change the "int" field, and it works the same way)
3- To delete a widget by the Dice use:
nomeDoVector.erase (nomeDoVector.begin()+ 2); //apaga o 3º elemento
or pass a variable, in this case int i = 5;
nomeDoVector.erase (nomeDoVector.begin()+ i); //i = 5 apaga o 6º elemento
(answering the second question, the vector fits itself )
ex:
[0,2,5,1,3] -> nameVector.Rase (nameVector.Begin()+ 2)
result:
[0,2,1,3] -> note that now the number "1" is the 3rd.
The situation is the same by eliminating at the beginning or end ?
Yes, Voce can use Erase to delete any element, including the first and last. But if you want Voce you can use it to make
nomeDoVector.pop_back();
it automatically finds who is the last and deletes.
OBS1: Voce can also delete several elements at once
thus:
nomeDoVector.erase(nomeDoVector.begin(),nomeDoVector.begin()+3);//apaga os elementos das posições 0,1 e 2.
What are you doing? Give some context, show where your problem is.
– Maniero
I already edited the post to be clearer.
– jorge saraiva
myvector.Erase (myvector.Begin()+Indice);
– EProgrammerNotFound
@And does the vector automatically change size after this instruction ? since if an element is eliminated its size will not stay the same.
– jorge saraiva