本蒟蒻于今天更新了自己的YuanShen代码,但是!出了亿些BUG,所以求助dalao为什么我这个代码会到输出
系统加载中
就会停止?
(保证所有文件准备齐全,编译环境没有问题)
#include<bits/stdc++.h>
#define int long long
#define map lis
using namespace std;
const int MAPMAX=1;
ofstream map_o,xy_o;
ifstream map_i,xy_i;
string order;
int player_x,player_y;
string world[MAPMAX];
void __init__();
void print();
namespace code{
void save(){ //保存存档
map_i.close();
map_o.open("map.txt");
for(int i=1;i<=MAPMAX;i++){
map_o<<world[i]+"endl"<<endl;
}
map_o.close();
}
void close(string s){ //关闭程序的方案
if(s=="exit"){
code::save();
cout<<"存档已保存"<<endl;
}
}
void inMap(){
for(int i=1;i<=MAPMAX;i++){
getline(map_i,world[i]);
}
}
}
signed main(){
__init__(); //初始化
while(true){ //主循环
// print();
cout<<"输入指令:"<<endl;
cin>>order;
code::close(order);
}
return 0;
}
void __init__(){ //初始化的方案
cout<<"系统加载中..."<<endl;
//载入地图
ifstream map_i("map.txt");
code::inMap();
if(map_i.is_open()) cout<<"地图加载完成。"<<endl;
else cout<<"地图载入错误,请重新启动。"<<endl,getchar();
//加载位置
ifstream xy_i("playerPlace.txt");
string Player_x,Player_y;
if(xy_i.is_open()){
std::getline(xy_i,Player_x);
std::getline(xy_i,Player_y);
xy_i.close();
}
else{
cout<<"坐标文件打开错误,请自行输入坐标 x y"<<endl<<"x=";
cin>>player_x;
cout<<endl<<"y=";
cin>>player_y;
}
cout<<"玩家位置加载完成。"<<"x="<<Player_x<<",y="<<Player_y<<endl;
getchar();
system("cls");
cout<<"系统载入完成。"<<endl<<"按下回车继续。";
getchar();
system("cls");
}