How can I create the map size,

#include <iostream>
#include <fstream>
#include<string>
using std::ifstream;
bool msize(int Height,int Width){

//add code

return true;
}
bool draw_map(char* Filename,int Width,int Height){

	if(Width<1||Height<1)
		return false;
	msize(Height,Width);
	ifstream file;
	file.open(Filename);

	if(file.is_open()){
			
		while(!file.eof()){	

			for(int x=0;x<Height;x++){

				for(int y=0;y<Width;y++){

					if(c!=']'){
						file >> map[x][y];
						file.get(c);

					}else 
						map[x][y] = -1;
				}
			}

		 }
		file.close();
	}
	return true;
}

I didn't see this post before responding in your other post.

I'd recommend using a std::vector<std::vector<int> > . You can then resize on the fly.

(not tested... just a guideline)

void msize(int Height,int Width,  std::vector<std::vector<int> > map)
{

map.resize(width); // you'll have to pick if the outer vector or the inner vectors are the rows or cols
for(unsigned int i = 0; i < map.size(); i++)
  {
  map[i].resize(height);
  }

}

David

Can you explain to me? Where is my mistake?

msize(3,3,int yourMap[i][j]);

Edited 6 Years Ago by alexchen: n/a

How can I write this map in my vector

bool msize(int Height,int Width, std::vector<std::vector<int> > map)
   
      {
   
    if(Height<1||Width<1)return false;

      map.resize(Width);
   
      for(unsigned int i = 0; i < map.size(); i++)
   
      {
   
      map[i].resize(Height);
   
      }
   return true;
       

      }
bool draw_map(char* Filename,int Width,int Height){
	
	if(Width<1||Height<1)
		return false;
	
	ifstream file;
	file.open(Filename);
	if(file.is_open()){

		while(!file.eof()){	

			for(int x=0;x<Height;x++){

				for(int y=0;y<Width;y++){

					if(c!=']'){
						file >> Map[x][y];
						file.get(c);

					}else 
						Map[x][y] = -1;
				}
			}

		 }
		file.close();
	
	}
	return true;
}

Edited 6 Years Ago by alexchen: n/a

alex,

Us telling you exactly where to put each character is not helpful for anyone involved. I'd suggest finding a basic c++ tutorial dealing with functions, arguments, and parameters. Compiling a few basic things and playing with them will help you get a handle on things. Then we can return to your vector question if you still have a problem.

David

This question has already been answered. Start a new discussion instead.