#include<fstream>
#include<string>
#define BUFFR_LEN 256
#define NIHLITY 0//虚无
#define WALL 1//墙
#define GROUND 2//地面
#define STD_GROUND 3//人站的地方
#define BOX 4//箱子
#define UNFINISHED 5//未完成的目标
#define FINISHED 6//
#define STD_UNFINISHED 7//完成的目标
#define T(N) ((N)+'0')
using namespace std;
class map{
private:
char **p;
int width;//宽
int height;//高
public:
void init(string filename){
char buf[BUFFR_LEN]
ifstream ifile(filename);
ifile.seekg(0,ios::beg);
ifile.getline(buf,BUFFR_LEN);
sscanf(buf,"%d x %d",&height,&width);
//行 height
//列 width
p = new int[height];
for(int i = 0; i < height; i++){
p[i] = new int[width];
ifile.getline(p[i],width);
}
ifile.close() ;
}
void prinMap(){
for(int i = 0; i < height; i++){
for(int j = 0; j < width; i++){
swich(p[i][j]){
case '0'+
using namespace std;
class map{
private:
char **p;
int width;//宽
int height;//高
public:
void init(string filename){
char buf[BUFFR_LEN]
ifstream ifile(filename);
ifile.seekg(0,ios::beg);
ifile.getline("地图.txt");
sscanf(buf,"%d x %d",&height,&width);
//行 height
//列 width
p = new int[height];
for(int i = 0; i < height; i++){
p[i] = new int[width];
for(int j=0;j<i;j++){
ifile.getline(p[i],width);
}
}
ifile.close() ;
void prinMap(){
string s[8]={" ","■"," ","★","■","□","■","☆"}
for(int i = 0; i < height; i++){
for(int j = 0; j < width; j++){
cout<<s[p[i][j]-'0'];
}
cout<<endl;
}
}
}
另一个使用这个的代码:
#include<fstream>
#include<iostream>
#include "map.h"
using namespace std;
int main(){
char buf[256];
map();
prinMap();
return 0;
}
(注:用c++解决)