Skip to content

Latest commit

 

History

History
67 lines (46 loc) · 1.06 KB

iterators.md

File metadata and controls

67 lines (46 loc) · 1.06 KB
description title ms.date ms.topic author ms.reviewer
Learn how to handle with Iterators
Iterators Handling
05/11/2023
conceptual
fejo-git
---

Iterators

definition

std::vector<string>::iterator i = names.begin();

The iterator is positioned at the beginning.

names.begin();

The iterator is positioned at the end.

names.end();

iterator with vector

for(std::vector<string>::iterator i = names.begin(); i < names.end(); i++) {
        std::cout << *i << std::endl;
}

An alternative and more common method.

for(const auto &name : names) {
    std::cout << " - " << name << std::endl;
}

compare iterators (storage)

std::vector<string>::iterator j = names.begin();
std::vector<string>::iterator i = names.end();
i--;
std::cout << (j < i) << std::endl;

// output 1

See also