9.4
#include<iostream> #include<vector> using namespace std; bool find(vector<int>::iterator a, vector<int>::iterator b, int n) { while (a != b) { if (*a == n) { return true; } else { a++; } } return false; } int main() { vector<int> iter = { 1,2,3,4,5,7 }; int n = 5; cout << find(iter.begin(), iter.end(), n)<<endl; return 0; }
9.11
#include<iostream> #include<vector> using namespace std; int main() { vector<int> v1; vector<int> v2 = { 1,2,3 }; vector<int> v3(v2); vector<int> v4(10); vector<int> v5(10, 5); vector<int> v6(vector<int>::iterator a, vector<int>::iterator b); }
9.13
list<int> a = {2,3,4}; vector<int> b(a.begin(), a.end()); vector<double> c(a.begin(), a.end());
9.14
list<const char*> t1; vector<string> t2; t2.assign(t1.cbegin(), t1.cend());
9.15
#include<iostream> #include<vector> #include<list> using namespace std; int main() { vector<int> a = { 1,2,3,4 }; vector<int> b = { 1,2,3,4 }; if (a == b) { cout << "equal" << endl; } else { cout << "no equal" << endl; } }
9.16
#include<iostream> #include<vector> #include<list> using namespace std; int main() { vector<int> a = { 1,2,3,4 }; list<int> b = { 1,2,3,4 }; vector<int> d;//直接比较会报错 d.assign(b.begin(), b.end()); if (a == d) { cout << "equal" << endl; } else { cout << "no equal" << endl; } }
9.18
#include<iostream> #include<string> #include<deque> using namespace std; int main() { string word; deque<string> iter; while (cin >> word) { iter.push_back(word); } auto a = iter.begin(); auto b = iter.end(); while (a != b) { cout << *a++ << endl; } return 0; }
9.19
#include<iostream> #include<string> #include<deque> #include<list> using namespace std; int main() { string word; list<string> iter; while (cin >> word) { iter.push_back(word); } auto a = iter.begin(); auto b = iter.end(); while (a != b) { cout << *a++ << endl; } return 0; }
明天接着.....