linux下练习 c++ 序列容器的使用
2012-10-15 19:04
351 查看
//sequence.cpp
//print.h
// sequence.cpp /* 序列式容器:vector,deque,list 插入:.insert(position,n,element), .insert(position,pos_begin,pos_end) 赋值:.assign(n,element), .assign(pos_begin,pos_end) 调整:.resize(n,element=value) 首尾:.front(),.back() 增删:.push_back(element), .pop_back()----删除,返回void */ #include <iostream> #include <deque> #include <string> #include "print.h" using namespace std; int main() { deque<string> ds; ds.push_back("zhang");//增加 ds.push_back("pu"); ds.push_back("yang"); ds.push_back("xie"); ds.insert(ds.begin()+1,1,"wang");//插入 string s1[3]={"liao","hu","liu"}; ds.insert(----ds.end(),s1,s1+3); print(ds.begin(),ds.end(),','); ds.pop_back(); //删除最后一个 ds.pop_back(); print(ds.begin(),ds.end(),','); ds.resize(10,"pkm");//大小设为10,后面用pkm填充 print(ds.begin(),ds.end(),','); ds.assign(5,"kkkkk");//5个,都为kkkkk print(ds.begin(),ds.end(),','); return 0; }
//print.h
//print.h #include <iostream> using namespace std; #ifndef print_fun #define print_fun template<typename T> ///显示序列数据 void print(T b,T e,char c=' ') { bool isExit=false; while (b!=e) { cout<<*b++<<c; isExit=true; } if(isExit) cout<<endl; } #endif
相关文章推荐
- linux下练习 c++ 普通容器的使用
- linux下练习 c++ 关联式容器共性测试,使用
- linux下练习 c++ 特殊容器、特殊函数的使用
- linux下练习 c++ 类库中list的特性、关联式容器共性介绍
- C++中防止STL中迭代器失效__map/set等关联容器vector/list/deque等序列容器_如何防止迭代器失效_即erase()的使用
- linux下练习 c++ 关联式容器map特性
- linux下练习 c++ 库函数排序使用举例
- linux下练习 c++ 容器的vector的特性
- C++ Vector 序列容器 之 使用vector和迭代器
- C++中防止STL中迭代器失效——map/set等关联容器——vector/list/deque等序列容器—如何防止迭代器失效—即erase()的使用
- linux下练习 c++ 容器的deque的特性
- C++中防止STL中迭代器失效__map/set等关联容器vector/list/deque等序列容器_如何防止迭代器失效_即erase()的使用
- linux下练习 c++ 关联式容器multimap特性
- C++ Vector 序列容器 之 使用vector和迭代器
- C++中防止STL中迭代器失效——map/set等关联容器——vector/list/deque等序列容器—如何防止迭代器失效—即erase()的使用
- [转]Ubuntu(Linux)使用Eclipse搭建C/C++编译环境
- 【C/C++】Linux下使用system()函数一定要谨慎
- linux c/c++ 编程之-----vim 基本使用
- C++ 使用表示容量的当个形参来初始化容器时,有没有使用copy constructor
- C++文本查询程序 C++Primer练习12.28 使用vector,map,set容器保存来自文件的数据并生成查询结果