CHAPTER8-26.cpp
上传用户:fjc899
上传日期:2007-07-03
资源大小:187k
文件大小:1k
- //文件名:CHAPTER8-26.cpp
- #include <list>
- #include <iostream>
- #if _MSC_VER > 1020 // if VC++ version is > 4.2
- using namespace std; // std c++ libs implemented in std
- #endif
- typedef list<int> LISTINT;
- void main()
- {
- LISTINT listOne;
- LISTINT listAnother;
- LISTINT::iterator i;
- // Add some data
- listOne.push_front (2);
- listOne.push_front (1);
- listOne.push_back (3);
- listAnother.push_front(4);
- listAnother.assign(listOne.begin(), listOne.end());
- // 1 2 3
- for (i = listAnother.begin(); i != listAnother.end(); ++i)
- cout << *i << " ";
- cout << endl;
- listAnother.assign(4, 1);
- // 1 1 1 1
- for (i = listAnother.begin(); i != listAnother.end(); ++i)
- cout << *i << " ";
- cout << endl;
- listAnother.erase(listAnother.begin());
- // 1 1 1
- for (i = listAnother.begin(); i != listAnother.end(); ++i)
- cout << *i << " ";
- cout << endl;
- listAnother.erase(listAnother.begin(), listAnother.end());
- if (listAnother.empty())
- cout << "All gonen";
- }