How do I find the length of an array?

前端 未结 27 2874
轮回少年
轮回少年 2020-11-21 23:10

Is there a way to find how many values an array has? Detecting whether or not I\'ve reached the end of an array would also work.

27条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-21 23:19

    In C++, using the std::array class to declare an array, one can easily find the size of an array and also the last element.

    #include
    #include
    int main()
    {
        std::array arr;
    
        //To find the size of the array
        std::cout<

    In fact, array class has a whole lot of other functions which let us use array a standard container.
    Reference 1 to C++ std::array class
    Reference 2 to std::array class
    The examples in the references are helpful.

提交回复
热议问题