Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion c++.md
Original file line number Diff line number Diff line change
Expand Up @@ -908,12 +908,20 @@ for (int i = 0; i < my_vector.size(); i++) {
std::cout << my_vector[i] << '\n'; // for accessing a vector's element we can use the operator []
}

// or using an iterator:
// or using an iterator (old fashion):
vector<string>::iterator it; // initialize the iterator for vector
for (it = my_vector.begin(); it != my_vector.end(); ++it) {
std::cout << *it << '\n';
}

// modern way of using an iterator
for (auto it = my_vector.begin(); it != my_vector.end(); ++it) {
std::cout << *it << '\n';
}
// (elegantly) or using the reference of the original object + using `auto` syntax
for (auto& it : vec) {
std::cout << it << std::endl;
}
// Set
// Sets are containers that store unique elements following a specific order.
// Set is a very useful container to store unique values in sorted order
Expand Down