Obtaining Information Using a Random Access Iterator - C++ STL

C++ examples for STL:iterator

Description

Obtaining Information Using a Random Access Iterator

Demo Code

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()/*from w  w w .  j  av a 2 s  . c  o m*/
{
    vector<string> Words;

    Words.push_back("Blue");
    Words.push_back("Green");
    Words.push_back("Teal");
    Words.push_back("Brick");
    Words.push_back("Purple");
    Words.push_back("Brown");
    Words.push_back("LightGray");

    // Define a random iterator.
    vector<string>::iterator Iter = Words.begin();

    // Access random points.
    Iter += 5;
    cout << *Iter << endl;

    Iter -= 2;
    cout << *Iter << endl;

    return 0;
}

Result


Related Tutorials