When
for (int ai : a) std::cout << ai;
is used for array – int a[20];
it can be substituted with
for (int i = 0; i < sizeof(a) / sizeof(a[0]); i++)
std::cout << a[i];
or with
for (int *ai = a; ai < a + (sizeof(a)/sizeof(*a)); ai++)
std::cout << *ai;
But to work with other collection, e.g. vector
iterators will be required:
std::vector<int> v(20);
// for (auto i : v) std::cout << i;
for (std::vector<int>::iterator vi = v.begin(); vi != v.end(); vi++)
std::cout << *vi;
solved Extended for loop in C++