Is there a prettier / less-verbose way to use iterators in C++? From the tutorials I've seen, I either set up typedefs everywhere (which gets tedious to do for a lot of one-off for-loops):
typedef std::vector<std:pair<int, int> >::iterator BlahIterator;
or have verbose-looking for loops like:
for (std::vector<std:pair<int, int> >::iterator it = ... ) ...
Is there a better way?
In C++11 you can use the range-based for loop combined with the auto keyword:
for (auto& it : v) ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With