• Advertisement

Archived

This topic is now archived and is closed to further replies.

Mac > XCode > C++ > Array Lengths!?

This topic is 5098 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I have a question. I am using XCode on a Mac with OSX and I have run into a simple problem. There is no nice drop down menu that displays the optional methods of the classes...I was just wondering how I get the length of a simple integer array. The code is like this: cin >> n; int myArray[n]; for(i = -1; i++ < myArrayLength - 1 myArray = -1; It does not like: myArray.length myArray.length() myArray.Length() myArray.Length myArray.rows() myArray.size myArray.size() I can''t come up with anything else and documentation is scarce... Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Arrays are not classes in C++, they are a native type. The only way to get the length of an array in C++ is to store it somewhere and then read it from that location. If you want a dynamic array-like container, I suggest you try using C++'s vector class instead.

[edited by - Extrarius on March 5, 2004 8:53:43 PM]

Share this post


Link to post
Share on other sites
Oh, my friend and I have been accustomed to Java and I have always used VB... I guess we just got used to having arrays be actual classes. That sucks though, thanks for the help.

Share this post


Link to post
Share on other sites
a vector or list is what you''re looking for, then.

probably a vector, if you''re already using arrays.

std::vector

Share this post


Link to post
Share on other sites
quote:
Original post by Krisc
for(i = -1; i++ < myArrayLength - 1
myArray = -1;
Thanks.



What kind of sick twisted person writes a for loop like this?!?! (j/k)
I strongly suggest you use the following instead:
for (i=0; i < myArrayLength; ++i)

Share this post


Link to post
Share on other sites

  • Advertisement