Archived

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

Vector of vectors, or, I suck at the STL

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

filling a vector of vectors with a maze... where mWidth is the width and mHeight is the height of the said maze. input being an ifstream.
std::vector<std::vector<int> > maze;
char w;

for(int x = 0; x < this->mWidth; ++x){
  //Should be doing something like creating a new vector...

  //maze.push_back(what goes in here.. a new vector or.. ?)

  for(int y = 0; y < this->mHeight; ++y){
    input >> w;
    //Putting w i there... 

    //maze[x].push_back(w); ?

  }
}
 
I can't seem to wrap my head around it... it'd be so easy using a char**... Yet I have want to learn to use the STL so I need your advice edit: template code doesn't play nicely with the [code] tag. Try using the [source] tag in the future. [edited by - SiCrane on May 28, 2004 1:29:43 AM]

Share this post


Link to post
Share on other sites
Off the top of my head:

std::vector<std::vector<int> > maze;

maze.resize(mWidth);
for(int x = 0; x < mWidth; ++x){
maze[x].resize(mHeight);
for(int y = 0; y < mHeight; ++y){
is >> maze[x][y];
}
}

Share this post


Link to post
Share on other sites