chapter6-21.cpp

来自「STL程序员开发指南源码」· C++ 代码 · 共 27 行

CPP
27
字号
//文件名:CHAPTER6-21.cpp
#pragma warning(disable:4786)
#include <iostream>
#include <vector>
using namespace std ;
typedef vector<int> INTVECTOR;
const ARRAY_SIZE = 10;
void Showvector(INTVECTOR &thevector);
void main()
{
    INTVECTOR thevector;
    for (int cEachItem = 0; cEachItem < ARRAY_SIZE; cEachItem++)
        thevector.push_back(cEachItem);
  thevector.erase(thevector.begin() + 5);
    Showvector(thevector);
    thevector.erase(thevector.begin(), thevector.end());
    Showvector(thevector);
}
void Showvector(INTVECTOR &thevector)
{   if (thevector.empty()) { cout << endl << "thevector is empty." << endl;   return;  }
    INTVECTOR::iterator theIterator;
  cout << endl << "thevector [ " ;
    for (theIterator = thevector.begin(); theIterator != thevector.end(); theIterator++)
    {   cout << *theIterator;  if (theIterator != thevector.end()-1) cout << ", "; }
    cout << " ]" << endl ;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?