1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
// 3.1415926535897932384626433832795
// PI stolen from Calc.exe
int main()
{
// assuming compiler is C++11 compiliant so can
// use initializer list.
vector<int> vec = {3,1,4,1,5,9,2,6,5,3,5,8,9,7,9,3};
remove(vec.begin(),vec.end(),3);
cout << "\n";
cout << "Remove all 5s\n";
// in C++11 could use auto instead of vector<int>::iterator for iter's type
for(vector<int>::iterator Pvec =vec.begin() ;Pvec != vec.end();++Pvec){
cout<< *Pvec;
cout << "\n";
}
cout << "\n";
return 0;
}
| |