// remove2.cpp - Erase all the zero elements in a vector. // This works, but would not be very // efficient for large vectors. #include #include using namespace std; void showVec(const vector &v) { cout << "\n "; int i; for(i=0; i v; v.push_back(5); v.push_back(1); v.push_back(0); v.push_back(-1); v.push_back(0); v.push_back(3); v.push_back(0); v.push_back(0); v.push_back(-4); v.push_back(0); showVec(v); vector::iterator it = v.begin(); while(it!=v.end()) if(*it==0) it = v.erase(it); else ++it; showVec(v); } 5, 1, 0, -1, 0, 3, 0, 0, -4, 0 5, 1, -1, 3, -4