std::vector iterator

suggest change

begin returns an iterator to the first element in the sequence container.

end returns an iterator to the first element past the end.

If the vector object is const, both begin and end return a const_iterator. If you want a const_iterator to be returned even if your vector is not const, you can use cbegin and cend.

Example:

#include <vector>
#include <iostream>

int main() {
    std::vector<int> v = { 1, 2, 3, 4, 5 };  //intialize vector using an initializer_list

    for (std::vector<int>::iterator it = v.begin(); it != v.end(); ++it) {
        std::cout << *it << " ";
    }

    return 0;
}

Output:

1 2 3 4 5

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Iterators:
* std::vector iterator

Table Of Contents
8 Arrays
11 Loops
36 Iterators
39 Streams
51 Unions
56 Lambdas
60 SFINAE
62 RAII
67 Sorting
84 RTTI
87 Scopes
104 Profiling
107 Recursion
117 Iteration
125 Alignment
134 Semaphore
136 Debugging
139 Mutexes
142 decltype