Пример #1
0
void main(void)
{
   // Dynamically allocated vector begins with 0 elements.
   INTVECTOR theVector;

   // Intialize the array to contain the members [100, 200, 300, 400]
   for (int cEachItem = 0; cEachItem < ARRAY_SIZE; cEachItem++)
      theVector.push_back((cEachItem + 1) * 100);

   cout << "First element: " << theVector.front() << endl;
   cout << "Last element: " << theVector.back() << endl;
   cout << "Elements in vector: " << theVector.size() << endl;

   // Delete the last element of the vector. Remember that the vector
   // is 0-based, so theVector.end() actually points 1 element beyond
   // the end.
   cout << "Deleting last element." << endl;
   theVector.erase(theVector.end() - 1);
   cout << "New last element is: " << theVector.back() << endl;

   // Delete the first element of the vector.
   cout << "Deleting first element." << endl;
   theVector.erase(theVector.begin());
   cout << "New first element is: " << theVector.front() << endl;
   cout << "Elements in vector: " << theVector.size() << endl;
 }
void main (void)
{
    //O vetor alocado dinamicamente inicia com 0 elementos.
    INTVECTOR vetor;

    //inicializa a matriz para conter os membros
    //[100,200,300,400]
    for (int cCadaItem = 0; cCadaItem < TAM_MATRIZ;cCadaItem++)
        vetor.push_back((cCadaItem + 1) * 100);

    cout << "Primeiro Elemento: " << vetor.front () << endl;
    cout << "Ultimo Elemento:  " << vetor.back () << endl;
    cout << "Elementos no vetor: " << vetor.size () << endl;

    /*Exclua o último elemento do vetor. Lembre-se de que o
    vetor inicia em 0, de modo que Vetor.end () na
    verdade aponta para 1 elemento  após o final. */

    cout << "Excluindo o ultimo elemento. " << endl;
    vetor.erase (vetor.end () - 1);
    cout << "O novo elemento e: " << vetor.back () << endl;
    //Exclua o primeiro elemento do vetor.
    cout << "Excluindo o primeiro elemento." << endl;
    vetor.erase (vetor.begin());
    cout << "O novo elemento e: " << vetor.front() << endl;
    cout << "Elementos no vetor: " << vetor.size() << endl;

}