标准模板库
==头文件== #ifndef PRINT_H #define PRINT_H 1
//输出一个指定区间中的所有数据(含头不含尾) #include
while(b!=e) cout<<*b++< #endif -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- /* 标准容器(类模板)共性: 构造函数:无参构造,拷贝构造,区间构造(两个迭代器表示的两个位置) 析构: 迭代器相关:正向 .begin(), .end(), 反向 .rbegin(), .rend() iterator,reverse_iterator,const_iterator,const_reverse_irerator * -> = ++ == != -- 插入:isert(pos,element),其中pos表示插入为位置,是一个迭代器 删除:.erase(pos), erase(pos_beg,pos_end) 清除:.clear() 大小:.size(), .max_size(), .empty() 交换:.swap(c2), swap(c1,c2) 运算符:= > < >= <= == != */ #include int a[5]={33,11,55,22,44}; vector vector for(int i=0;i<5;i++) cout< print(vi.begin(),vi.end()); print(a,a+5); print(vi.rbegin(),vi.rend()); b=vi.begin(); vi.insert(++++b,66);//在指定位置插入数据 vi.insert(vi.begin(),77); vi.insert(vi.end(),88); print(vi.begin(),vi.end()); cout< vi.erase(++++vi.begin(),--vi.end());//删除区间 print(vi.begin(),vi.end()); vector cout<<\ print(vi.begin(),vi.end()); print(v2.begin(),v2.end()); swap(vi,v2); cout<<\ print(vi.begin(),vi.end()); print(v2.begin(),v2.end()); vector cout<<\ print(vi.begin(),vi.end()); print(v2.begin(),v2.end()); vi.clear(); cout< cout<<\当前容量:\} /* 5 11 22 33 44 55 33 11 55 22 44 11 22 33 44 55 33 11 55 22 44 55 44 33 22 11 77 11 22 66 33 44 55 88 8/1073741823 77 11 22 66 33 55 88 77 11 88 33 11 55 22 44 --------------------------- 33 11 55 22 44 77 11 88 --------------------------- 77 11 88 33 11 55 22 44 ========================= 33 11 55 22 44 77 11 88 0 vector当前容量:0 */ -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-vector容器共性 #include int a[5]={33,11,55,22,44}; vector vector for(int i=0;i<5;i++) cout< print(vi.begin(),vi.end()); print(a,a+5); print(vi.rbegin(),vi.rend()); b=vi.begin(); vi.insert(++++b,66);//在指定位置插入数据 vi.insert(vi.begin(),77); vi.insert(vi.end(),88); print(vi.begin(),vi.end()); cout< vi.erase(++++vi.begin(),--vi.end());//删除区间 print(vi.begin(),vi.end()); vector cout<<\ print(vi.begin(),vi.end()); print(v2.begin(),v2.end()); swap(vi,v2); cout<<\ print(vi.begin(),vi.end()); print(v2.begin(),v2.end()); vector