How do I find the length of an array?

前端 未结 27 2876
轮回少年
轮回少年 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:28

    A good solution that uses generics:

    template 
    inline unsigned arraysize(const T (&v)[S]) { return S; }
    

    Then simply call arraysize(_Array); to get the length of the array.

    Source

提交回复
热议问题