• ### What is your GameDev Story?

Public Group

#### Archived

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

# Vector of vectors, or, I suck at the STL

This topic is 5348 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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];    }  }

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 13
• 9
• 15
• 14
• 46
• ### Forum Statistics

• Total Topics
634064
• Total Posts
3015308
×