C++ ファイル入出力について
Posted: 2011年1月18日(火) 21:39
struct CharaStatus{}
CharaStatus Knight={1,30,30,15,5,5,5,40,40,300,300,50,50,0};
CharaStatus thief={1,15,25,30,5,30,5,30,30,250,250,50,50,0};
CharaStatus bishop={1,15,20,10,30,10,30,25,25,200,200,300,300,0};
CharaStatus wizard={1,10,15,5,40,10,5,20,20,150,150,400,400,0};
Mapx=10;
Mapy=10;
story=0;
locat=1;
char t;
sint s;
cout<<"始めから[n]"<<endl;
cout<<"続きから[c]"<<endl;
cin >>t;
s=t;
if(t=='c'){
cout<<"ゲームを続きから開始します"<<endl;
ifstream fin("save.txt");
if(!fin){
cout<<"ファイルオープンに失敗しました\n";
}
else{
for(k=1;k<=5;k++){
fin>>temp.Lv>>temp.Str>>temp.Vit>>temp.Dex>>temp.Wis>>temp.Luc
>>temp.Faith>>temp.Wepon>>temp.Gard>>temp.maxhp>>temp.hp
>>temp.maxmp>>temp.mp>>temp.exp;
switch(k){
case 1:
Knight =temp;
break;
case 2:
thief=temp;
break;
case 3:
bishop=temp;
break;
case 4:
wizard=temp;
break;
case 5:
fin>>Money>>Mapx>>Mapy>>story>>locat;
break;
}
}
fin.close();
}}
else if(t=='n'){
cout<<"初めから開始します"<<endl;}
cout <<"セーブを実行しますか?\n";
cout <<"[y][n]";
cin>>t;
if(t=='y'){
cout <<"セーブを実行します\n";
ofstream fout("seve.txt");
if(!fout){
cout<<"ファイルをオープンできませんでした。\n";;
}
else{
cout<<"ファイルをオープンしました。\n";
for(k=1;k<=5;k++){
switch(k){
case 1:
temp =Knight;
break;
case 2:
temp=thief;
break;
case 3:
temp = bishop;
break;
case 4:
temp = wizard;
break;
}
if(k==5){fout<<Money<<endl<<Mapx<<endl<<Mapy<<endl<<story<<endl<<locat<<endl;break;}
fout<<temp.Lv<<endl<<temp.Str<<endl<<temp.Vit<<endl<<temp.Dex<<endl<<temp.Wis<<endl<<temp.Luc
<<endl<<temp.Faith<<endl<<temp.Wepon<<endl<<temp.Gard<<endl<<temp.maxhp<<endl<<temp.hp
<<endl<<temp.maxmp<<endl<<temp.mp<<endl<<temp.exp<<endl;
}
fout.close();
cout<<"セーブを行いました。\n";
}
cin>>t;}
else cout<<"セーブをせずに終了\n";
}Cを少しかじった程度で作っているので変なところなど多々あると思いますがご教示願います