std::vector<int> v = {0, 1, 2, 3, 4, 5};
for (auto i : v)
{
// access by value, the type of i is int
std::cout << i << ' ';
}
std::cout << '\n';
I found this as part of another question
How to navigate through a vector using iterators? (C++)
I would like to know how the following works ?
for (auto i : v)
will navigate the entire vector, I need this information because I want to implement a custom vector class. In order to create custom vector class, do I need to create the begin()
, end()
functions and iterator member variable in it?