Archived

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

Is there a 2D version of the STL vector?

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