This is a java code.
for (int j = 0; j < charArray[i].length; j++) {
System.out.print(charArray[i][j]);
}
Very simple question, how I make the java length property but in c++?
This is a java code.
for (int j = 0; j < charArray[i].length; j++) {
System.out.print(charArray[i][j]);
}
Very simple question, how I make the java length property but in c++?
You can make a function call by passing the array pointer and you can check if the pointer is null by
if (charArray != 0)
then you can try this
sizeof(charArray)/sizeof(charArray[0])
template <typename T,unsigned S>
inline unsigned arraysize(const T (&v)[S]) { return S; }
The compiler will try to create a function, based on the template, that matches the size of the array. I take no credit for the answer, see the link below, with a lengthier explanation.
http://www.cplusplus.com/forum/general/33669/
It doesn't work for a dynamically allocated array, but it gives you a compiler error. Does anything work for a dynamically allocated array?
Just do this:
for(int a=0; charArray[a] != '\0' ; a++);
This will store the length of charArray in 'a'