Is there any inbuilt function in cpp that can give me the length of a 2d char array
for ex, the function for args
const char* args[] = {"412", "..7", ".58", "7.8", "32.", "6..", "351", "3.9", "985", "...", ".46"}
should return 11
I like to use a template function for this.
template <typename T, std::size_t N>
std::size_t size(T(&)[N]) { return N; }
The advantage over an approach using sizeof
is that you can't accidentally do it with a pointer.
这将给出args
中元素的数量:
sizeof(args) / sizeof(args[0])
在C ++ 11中,您可以使用:
std::end(args) - std::begin(args)
sizeof(args) / sizeof(*args)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.