ababup1192
6/18/2017 - 2:13 AM

vector.cpp

#include <iostream>
#include <vector>

// http://vivi.dyndns.org/tech/cpp/vector.html

int main(){
    std::vector<int> v;
    std::vector<int>::iterator itr;

    v.push_back(1);
    v.push_back(2);
    v.push_back(3);

    for(itr = v.begin(); itr != v.end(); ++itr) {
        std::cout << *itr << " ";
    }
    std::cout << std::endl;

    v.push_back(4);
    v.push_back(5);
    v.push_back(6);

    for(itr = v.begin(); itr != v.end(); ++itr) {
        std::cout << *itr << " ";
    }
    std::cout << std::endl;

    v.insert(v.begin() + 4, 100);

    for(itr = v.begin(); itr != v.end(); ++itr) {
        std::cout << *itr << " ";
    }
    std::cout << std::endl;

    v.pop_back();
    v.pop_back();
    for(itr = v.begin(); itr != v.end(); ++itr) {
        std::cout << *itr << " ";
    }
    std::cout << std::endl;
    std::cout << "size:" << v.size() << std::endl;

    return 0;
}