description | title | ms.date | ms.topic | author | ms.reviewer |
---|---|---|---|---|---|
Learn how to handle with Iterators |
Iterators Handling |
05/11/2023 |
conceptual |
fejo-git |
--- |
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();
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;
}
std::vector<string>::iterator j = names.begin();
std::vector<string>::iterator i = names.end();
i--;
std::cout << (j < i) << std::endl;
// output 1