Tag:delete int inf ++ Array Share push element bsp
vector<int> num; for (int i=0; i<10; ++i) Num.push_back (i); Num.push_back (ten); Num.push_back (ten); cout << "Original array:\n"; Vector<int>::iterator it; C++11 used before, after 11 can be used auto for (auto It=num.begin (); It!=num.end (); ++it) { cout << *it << " "; } cout << Endl; Num.insert (Num.begin () +2,3,10); Before num[2] Add 3 cout << "Inserted array:\n"; for (auto It=num.begin (); It!=num.end (); ++it) { cout << *it << " "; } cout << Endl; Delete Ten for (Auto It=num.begin (); It!=num.end (); ++it) { if (*it = =) { num.erase (it); /Remove the element that it points to, then it automatically points to the next element --it;} } cout << "Deleted array:\n"; for (auto It=num.begin (); It!=num.end (); ++it) { cout << *it << " "; }
Operation Result:
Simple usage of vector dynamic array (a container) in CPP