In the intermediate lesson “3- Determining the Size of Arrays” Mosh introduces the size() function to determine the size of an array. However, it doesn’t work on my system (macOS, CLion, C++20).
Does anybody else have that problem?
It does work though if I define an arrays differently:
array<int, 3> my_array;
cout << my_array.size();
I also read that it is better to use vectors than arrays. But I think vectors are not included in this course.
The size function is called as size(my_array) (or std::size(my_array) if not in namespace std). It is not a method on some array class. You also need to make sure you included the appropriate header files to get access to the size function.
Sorry you are mixing two different things. There is the struct std::array that you are importing and using in the second screenshot which is different than the primitive arrays. Your first screenshot shows the primitive array called numbers.
To make the first one work, I think you just need the correct header which I think is iterator: #include <iterator> (would have to double check the documentation to be sure that was the correct header).