Public Group

# finding the size of a vector?

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

## Recommended Posts

hi, how to i find the size of a vector? size always seems to = 1?

##### Share on other sites
delete this this if you would, i figured it out.

##### Share on other sites
What kind of vector are you talking about? A C++ std::vector or a Java java.util.Vector would use the .size() member function.

##### Share on other sites
What kind of vector?

An C++ STL vector:

std::vector <x> vec;
unsigned int size = vec.size ();

Or if you meant the length of a math vector:

float len = sqrt (x*x + y*y + z*z);

Edit: Thank you DaBono. I intended to write float. Updated for correctness.

##### Share on other sites
@CJWR: Wow, a solution in 41 seconds.. I wish I was as quick all the time :-).
@skittleo: Be careful with the int len = ..., that could result in some nasty chopping errors.

##### Share on other sites
Quote:
 Original post by DaBono@CJWR: Wow, a solution in 41 seconds.. I wish I was as quick all the time :-).@skittleo: Be careful with the int len = ..., that could result in some nasty chopping errors.

well, it was a 2d vector of size 1. i was going name.size(), which as it should returned 1. however i wanted the szie of name[1]. so once i tried name[1].size(), and it worked. this is work i get for posting before i think. :(

##### Share on other sites
skittleo, not to be nitpicky, but wouldn't the integer size of a mathematical vector be kind of useless (if used for any important calculations)?

:p I know it was just an example, but I feel randomly nitpicky.

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633704
• Total Posts
3013460
×