C-style arrays do not have member methods, such as size()
. Standard containers, like std::array
and std::vector
, have size()
methods, eg:
#include <iostream>
#include <array>
std::array<int, 3> arr{1,2,3};
int main()
{
std::cout << arr.size() << std::endl;
}
#include <iostream>
#include <vector>
std::vector<int> arr{1,2,3};
int main()
{
std::cout << arr.size() << std::endl;
}
There is also a std::size()
function, which has overloads to work with standard containers, as well as C-style arrays, eg:
#include <iostream>
#include <array>
int arr[] = {1,2,3};
int main()
{
std::cout << std::size(arr) << std::endl;
}