CHAPTER6-21.cpp
上传用户:fjc899
上传日期:2007-07-03
资源大小:187k
文件大小:1k
源码类别:

STL

开发平台:

C/C++

  1. //文件名:CHAPTER6-21.cpp
  2. #pragma warning(disable:4786)
  3. #include <iostream>
  4. #include <vector>
  5. using namespace std ;
  6. typedef vector<int> INTVECTOR;
  7. const ARRAY_SIZE = 10;
  8. void Showvector(INTVECTOR &thevector);
  9. void main()
  10. {
  11.     INTVECTOR thevector;
  12.     for (int cEachItem = 0; cEachItem < ARRAY_SIZE; cEachItem++)
  13.         thevector.push_back(cEachItem);
  14.   thevector.erase(thevector.begin() + 5);
  15.     Showvector(thevector);
  16.     thevector.erase(thevector.begin(), thevector.end());
  17.     Showvector(thevector);
  18. }
  19. void Showvector(INTVECTOR &thevector)
  20. {   if (thevector.empty()) { cout << endl << "thevector is empty." << endl;   return;  }
  21.     INTVECTOR::iterator theIterator;
  22.   cout << endl << "thevector [ " ;
  23.     for (theIterator = thevector.begin(); theIterator != thevector.end(); theIterator++)
  24.     {   cout << *theIterator;  if (theIterator != thevector.end()-1) cout << ", "; }
  25.     cout << " ]" << endl ;
  26. }