How do I find the length of an array?

前端 未结 27 2940
轮回少年
轮回少年 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条回答
  •  闹比i
    闹比i (楼主)
    2020-11-21 23:31

    Instead of using the built in array function aka:

     int x[3] = {0, 1, 2};
    

    you should use the array class and the array template. Try:

    #include 
    array Name_of_Array = {};
    

    So now if you want to find the length of the array, all you have to do is using the size function in the array class.

    Name_of_Array.size();
    

    and that should return the length of elements in the array.

提交回复
热议问题