vectorarr = {1, 2, 3, 4, 5}; for (auto it = arr.begin(); it != arr.end(); ++it) { cout << *it << " "; }
string str = "Hello, World!"; for (auto it = str.begin(); it != str.end(); ++it) { cout << *it << " "; }This example is similar to the first example, but it iterates over a string instead of a vector. The end function is used to specify the end of the string range. This code also belongs to the C++ STL library.