(assuming that I can not use STL container)
#include <iostream>
int main()
{
wchar_t my_array[] = { L'h', L'e', L'l', L'l', L'o' };
for (const auto& wch : my_array) {
std::wcout << wch;
}
}
The range-based for loop in C++ uses the begin()
and end()
functions to determine the range of elements to iterate over. In the case of an array, as above, std::begin(my_array)
returns a pointer to the first element of the array, and std::end(my_array)
returns a pointer to one past the last element of the array.
It works, but is it UB?