I want to delete an element in a 2d vector
, say [1][1]
in Field
, which is a 4x5 vector
I tried
Field.erase([1][1]);
I know that for a 1d vector
, I would just do
Field.erase (Field.begin()+1)
but what about for 2d vectors
?
All the elements of the vector are removed using clear() function. erase() function, on the other hand, is used to remove specific elements from the container or a range of elements from the container, thus reducing its size by the number of elements removed.
To remove a single copy of an element from a std::vector , you can use std::find and the std::vector 's erase member function like this: auto itr = std::find(v. begin(), v. end(), rnames); if (itr !=
Field[1].erase(Field[1].begin() + 1);
That's how you erase an element. But by your comments, that's not what you really want. What you actually want is to clear the value of the element to it's default value. For that:
Field[1][1] = Card();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With