In python, you can iterate a list like below. Is there a similarly short way of doing this in C++?
list = [1,2,3,4,5]
for i, num in enumerate(list):
# do stuff
Something like for(int num : list)
is close, but not the same.
In python, you can iterate a list like below. Is there a similarly short way of doing this in C++?
list = [1,2,3,4,5]
for i, num in enumerate(list):
# do stuff
Something like for(int num : list)
is close, but not the same.
C++ 17 time!
for(auto [it, i] = tuple{list.begin(), 0}; it != list.end(); it++, i++)
{
cout << *it; //actual item
cout << i; //index value
}