1 說明:目的是為了將vector裡 符合isdel==true的元素刪掉。
2 實現代碼
#include "stdafx.h" #include #include#include using namespace std; class Test { public: Test(bool isdel) { this->is_delete=isdel; } bool is_delete; }; void print(vector &v) { std::vector ::iterator iter; for(iter=v.begin();iter!=v.end();++iter) { cout<<(*iter).is_delete<<" "; assert(!(*iter).is_delete); } cout< &v,bool b) { Test *t= new Test(b); v.push_back(*t); delete t; cout< &v) { std::vector ::iterator iter; for(iter=v.begin();iter!=v.end();) { if((*iter).is_delete==true) { iter=v.erase(iter); } else { ++iter; } } } int _tmain(int argc, _TCHAR* argv[]) { vector svec; std::vector ::iterator iter; srand(time(NULL)); cout<<"隨機賦值:"<