CHAPTER7-16.cpp
上传用户:fjc899
上传日期:2007-07-03
资源大小:187k
文件大小:1k
- //文件名:CHAPTER7-16.cpp
- #include <iostream>
- #include <deque>
- #if _MSC_VER > 1020 // if VC++ version is > 4.2
- using namespace std; // std c++ libs implemented in std
- #endif
- typedef deque<char > CHARDEQUE;
- void print_contents (CHARDEQUE deque, char*);
- int main()
- {
- CHARDEQUE a(3,'A'); //定义了变量a,内容是3个'A'
- CHARDEQUE b(4,'B'); //定义了变量b,内容是4个'B'
- print_contents (a,"a");
- print_contents (b,"b");
- a.swap(b); //内容互换
- print_contents (a,"a");
- print_contents (b,"b");
- a.swap(b);//内容换回来
- print_contents (a,"a");
- print_contents (b,"b");
- a.assign(b.begin(),b.end());
- print_contents (a,"a");
- a.assign(b.begin(),b.begin()+2);
- print_contents (a,"a");
- a.assign(3,'Z');
- print_contents (a,"a");
- return 0;
- }
- //下面是显示函数源代码
- void print_contents (CHARDEQUE deque, char *name)
- {
- CHARDEQUE::iterator pdeque;
- cout <<"The contents of "<< name <<" : ";
- for(pdeque = deque.begin();
- pdeque != deque.end();
- pdeque++)
- {
- cout << *pdeque <<" " ;
- }
- cout<<endl;
- }