Jump to content
  • Advertisement

Archived

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

Anthracks

Is there a 2D version of the STL vector?

This topic is 6154 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

I''m a newbie to the STL, and I was wondering, is there anything like a 2D array in it? My first thought was something like
  
vector<int, int> someArray;
  
But that wouldn''t compile (I''m using Visual C++ 6). I also tried
  
vector<vector<int>> someArray;
  
But that wouldn''t compile either. Am I trying to do the impossible? Thanks, Anthracks

Share this post


Link to post
Share on other sites
Advertisement
As with arrays you would have an array of array''s - you can have a vector of vectors, declared thus:

  
std::vector< std::vector<int> > vec2d;


this compiles at least, I haven''t tried populating it but I can''t see why it wouldn''t work?

Share this post


Link to post
Share on other sites
  
vector<vector<int>> someArray;


That would work, but you have to be careful how you type it. In the line above, you have the >> operator (just after the int). You need a space between the two angle brackets for the line to parse correctly.


Aren`t templates fun

EDIT: Quote and source tags got mangled

Edited by - Krunk on November 15, 2001 5:19:57 PM

Share this post


Link to post
Share on other sites
Ah, thanks Krunk, you got it . I thought doing that made sense, I just didn't think of the lousy >> operator mixing things up.

Thanks all!

Anthracks

Edited by - Anthracks on November 15, 2001 5:54:01 PM

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!