vectorler

kaynak

#include "stdafx.h"

#include <iostream>
#include <vector>

using namespace std;

int main() {

    vector <unsigned char> test_vector;

    cout << "vector baslangic uzunlugu = " << test_vector.size() << endl; 

    for (unsigned int i = 0; i < 5; i++)
    {
        test_vector.push_back(i); // vector sonuna ekleme
    }

    cout << "vector sonuna 0-4 arasi degerler eklendikten sonra vector uzunlugu = " << test_vector.size() << endl;

    cout << "vectorun son elemani = " << (int)test_vector.back() << endl; 

    test_vector.pop_back(); // sondaki elemani cikarma

    cout << "vectorden son eleman cikarildiktan sonra son eleman = " << (int)test_vector.back() << endl;

    cout << "vectorden son eleman cikarildiktan sonra vector uzunlugu = " << test_vector.size() << endl;

    // vector icindeki degerlerin tek tek ekrana basilmasi.
    for ( unsigned int i = 0; i < 4; i++)
    {
        cout << "vectorun " << i << ". elemani = " << (int) test_vector[i] << endl;
    }

    test_vector.clear(); // vector temizleme

    cout << "vector temizlendikten sonra vector uzunlugu = " << test_vector.size() << endl;

    return 0;
}