Jump to content
  • Advertisement
Sign in to follow this  
CJWR

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.

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

Recommended Posts

Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!