CHAPTER8-14.cpp
上传用户:fjc899
上传日期:2007-07-03
资源大小:187k
文件大小:1k
- //文件名:CHAPTER8-14.cpp
- #include <iostream>
- #include <list>
- #if _MSC_VER > 1020 // if VC++ version is > 4.2
- using namespace std; // std c++ libs implemented in std
- #endif
- typedef list<char > CHARLIST;
- void print_contents (CHARLIST list, char*);
- void main()
- { //create a with A, B, C and D
- CHARLIST a;
- a.push_back('A');
- a.push_back('B');
- a.push_back('C');
- a.push_back('D');
- //print out the contents
- print_contents (a,"a");
- cout <<"max_size of a is " <<a.max_size() <<endl;
- cout <<"size of a is " <<a.size() <<endl;
- //let us increase the size to 10
- // and set the new elements to be 'X'
- a.resize(10,'X');
- print_contents (a,"a");
- cout <<"size of a is " <<a.size() <<endl;
- //let us resize it to 5
- a.resize(5);
- print_contents (a,"a");
- cout <<"size of a is " <<a.size() <<endl;
- cout <<"max_size of a is still " <<a.max_size() <<endl;
- }
- //function to print the contents of list
- void print_contents (CHARLIST list, char *name)
- {
- CHARLIST::iterator plist;
- cout <<"The contents of "<< name <<" : ";
- for(plist = list.begin(); plist != list.end(); plist++)
- { cout << *plist <<" " ;}
- cout<<endl;
- }