本文共 1451 字,大约阅读时间需要 4 分钟。
阅读并运行程序,解释程序执行得到的结果
(1)
#include#include #include using namespace std;int main(){ vector ivec; int i; for(i = 0; i < 5; i++ ) ivec.push_back(i); for(i = 0; i < 5; i++) cout< <<" "; cout<
(2)
#include#include using namespace std;int main(){ vector intList; vector ::iterator listIt; int i; intList.push_back(1); intList.push_back(5); intList.push_back(10); intList.push_back(15); cout<<"Line 1: List Elements: "; for(i=0; i<4; i++) cout< <<" "; cout<
(3)
#include#include #include
#include using namespace std;int main(){ int ia[5] = { 1,2,3,4}; list id(ia, ia+4); ostream_iterator outite(cout, " "); copy(id.begin(), id.end(), outite); cout << endl; copy(ia+1, ia+2, front_inserter(id)); copy(id.begin(), id.end(), outite); cout << endl; copy(ia+3, ia+4, back_inserter(id)); copy(id.begin(), id.end(), outite); cout << endl; list ::iterator ite = find(id.begin(), id.end(), 3); copy(ia+0, ia+2, inserter(id, ite)); copy(id.begin(), id.end(), outite); cout << endl; copy(id.rbegin(), id.rend(), outite); cout << endl; return 0;}
转载地址:http://zqkul.baihongyu.com/