C++ Vector - Remove First Element - Tutorial Kart

C++ Vector ? Remove First Element

C++ Vector ? Remove First Element

To remove first element of a vector, you can use erase() function. Pass iterator to first element of the vector as argument to erase() function.

Example ? Remove or Delete First Element of Vector

In the following example, we have defined a vector and initialized with some values. We shall use erase() to remove the first element.

C++ Program

#include #include using namespace std; int main() {

vector nums; nums.push_back(6); nums.push_back(2); nums.push_back(7); nums.push_back(1); nums.erase(nums.begin()); for (int num: nums)

cout ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download