To delete a single element, you could do:
std::vector<int> vec; vec.push_back(6); vec.push_back(-17); vec.push_back(12); // Deletes the second element (vec[1]) vec.erase(std::next(vec.begin()));
Or, to delete more than one element at once:
// Deletes the second through third elements (vec[1], vec[2]) vec.erase(std::next(vec.begin(), 1), std::next(vec.begin(), 3));
Related Posts:
- C++ Erase vector element by value rather than by position?
- What is the easiest way to initialize a std::vector with hardcoded elements?
- Is it more efficient to copy a vector by reserving and copying, or by creating and swapping? [duplicate]
- How do I reverse a C++ vector?
- What’s the most efficient way to erase duplicates and sort a vector?
- Best way to extract a subvector from a vector?
- Appending a vector to a vector
- Why can’t I make a vector of references?
- Displaying contents of a vector container in C++
- How to implement 2D vector array?
- Vector of Vectors to create matrix
- How to find out if an item is present in a std::vector?
- How do I print out the contents of a vector?
- check if a std::vector contains a certain object?
- How to navigate through a vector using iterators? (C++)
- C++ for each, pulling from vector elements
- Debug assertion failed. C++ vector subscript out of range
- A proper way to create a matrix in c++
- No matching member function for call to ‘push_back’ error
- Pass a vector by reference C++
- Why there is no pop_front method in C++ std::vector?
- Initializing a two dimensional std::vector
- C++ – No matching member function for call to ‘push_back’
- Debug assertion failed. C++ vector subscript out of range
- Vector is not a Template?
- Displaying a vector of strings in C++
- ‘vector’ in namespace ‘std’ does not have a template type
- push_back vs emplace_back
- C++ error: Undefined symbols for architecture x86_64
- Vector of structs initialization
- Converting a vector
to string - vector
::size_type in C++ - Parsing a comma-delimited std::string
- How to ensure that a std::map is ordered?
- Why use a new call with a C++ ‘vector’?
- Why doesn’t std::vector::push_front() exist?
- C++ delete vector, objects, free memory
- How to iterate over a vector?
- How to access the contents of a vector from a pointer to the vector in C++?
- Insert object at index of vector c++
- How to convert vector to array
- push_back vs emplace_back
- No operator << matches these operands
- Initialize empty vector in structure – c++
- splitting a string into an array in C++ without using vector
- Remove spaces from std::string in C++
- What is the difference between const_iterator and non-const iterator in the C++ STL?
- Remove spaces from std::string in C++
- How to check that an element is in a std::set?
- How to sum up elements of a C++ vector?
- Implementation of Vector in C++
- Determine if map contains a value for a key?
- How to initialize a vector of pointers
- C++ Remove punctuation from String
- Correct way to work with vector of arrays
- C++ error: double free or corruption (fasttop)
- How to get current time in milliseconds?
- Use the auto keyword in C++ STL
- error C2106: ‘=’ : left operand must be l-value
- I get this error: “glibc detected”
- std::string length() and size() member functions
- How to create a vector of class objects in C++?
- “vector” was not declared in this scope
- sorting in std::map where key is a std::string
- How to do std::string indexof in C++ that returns index of matching string?
- Vector declaration “expected parameter declarator”
- Why is this vector iterator not incrementable?
- C++ equivalent of StringBuffer/StringBuilder?
- What is the size of sizeof(vector)? C++
- List iterator not dereferencable?
- c++ vector bubble sort
- clearing a vector of pointers [duplicate]
- “Cannot allocate an object of abstract type” error
- C++ equivalent of Java’s toString?
- Is there any built-in factorial function in c++?
- C++ struct constructor
- When to use virtual destructors?
- What is uintptr_t data type
- Why do we use volatile keyword? [duplicate]
- C++ round a double up to 2 decimal places
- Windows 7 exception code: 0xc0000409
- Convert float to std::string in C++
- warning: control may reach end of non-void function
- Error at constructor : Expected an identifier?
- identifier “string” undefined?
- What does LPCWSTR stand for and how should it be handled with?
- error: request for member ‘..’ in ‘..’ which is of non-class type
- Socket API or library for C++?
- What does it mean that “a declaration shadows a parameter”?
- error C2601: ‘main’ : local function definitions are illegall – MS VS 2013 Compiler
- How to convert QString to int?
- Update GCC on OSX
- Which is faster C++ String length() or size()?
- creating an array of structs in c++
- Function stoi not declared
- How to Check the Version of my gcc?
- Difference between function arguments declared with & and * in C++
- C++ floating point to integer type conversions
- How to get an average in C++?
- C++: variable ‘std::ifstream ifs’ has initializer but incomplete type