4 ms·
> Calculating the size of static array In C++17 you can do #include <array> std::array myarray{ 4, 5, 6, 7, 8, 9 }; int my_size = myarray.size();
by stabbles 9y ago
> Calculating the size of static array
In C++17 you can do
#include <array>
std::array myarray{ 4, 5, 6, 7, 8, 9 };
int my_size = myarray.size(); // returns 6
which even deducts the type `std::array<int, 6>` for you.
- ender341341 9y agoor just use std::extent which type safely gets the size of arrays (though most of my new c++ will probably be using std::array)
- mattnewport 9y agoYou can also use the std::size() free function to get the size of a C array, an std::array or any other standard container. http://en.cppreference.com/w/cpp/iterator/size http://en.cppreference.com/w/cpp/iterator/size
- stabbles 9y agoA free function for this looks even better IMO.