Is there a 2D version of the STL vector?

Started by
3 comments, last by Anthracks 22 years, 5 months ago
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
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?
"Absorb what is useful, reject what is useless, and add what is specifically your own." - Lee Jun Fan
you have to do

vector intvector; 

  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
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

This topic is closed to new replies.

Advertisement