I’m new to c++. I just want to declare an array and find its size. How do I do this? I keep getting a character count or something.
string vidArray[] = {"fingers.mov","motion_test.mov"};
int numVids = vidArray->size();
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
First of all the vidArray->size() call you made is equivalent to vidArray[0].call() because an array is nothing else than a pointer pointing the first element, so by calling vidArray->size() you are simply doing : (*vidArray).size().
Such old arrays doesn’t have a size(), there are however unadvisable hacks based on macros to get the count of an array :
This will return you the array size, but this isn’t a great thing (Explanations), that’s why I would advise you to use an std::vector if you need dynamic resizing :
That you can also initialize this way with boost::assign (Documentation)
Or a boost::array (Documentation) if you want an array which cannot vary in size (i.e. As stated by Walter in the comments, if you are already using c++11 you can use std::array which is boost::array but in the standard library)