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.
sizeof A/sizeof A[0], returns the wrong number when passed a pointer. Failing to compile is always better than giving the wrong answer.sizeof(args)/sizeof(args[0]); and it works :) I didn't want to go for templates, I don't know how to Initialize a 2d string array in them.This will give the number of elements in args:
sizeof(args) / sizeof(args[0])
std::vector<std::string>rather than achar *args[]. That way, you do get functions that work.