前情提要:https://www.luogu.com.cn/discuss/700536
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
string ty[]={"姓名","性别","种族"};
void CreatOC(void){
system("cls");
ofstream file;
file.open("OCData.txt",ios::out);
file<<"--------我是分隔符--------"<<endl;
string a;
printf("现在进入新建界面。\n");
int i=0;
while(i<3){
cout<<"请输入OC"<<ty[i]<<":";
cin>>a;
file<<ty[i]<<":"<<a<<endl;
i++;
}
printf("新建完成。\n");
file.close();
}
void Show()
{
system("cls");
ifstream file;
file.open("OCData.txt",ios::in);
if (!file.is_open())
{
cout << "文件打开失败,请检查文件路径!"<<endl;
return;
}
char c[1024];
while (file >> c)
{
cout << c << endl;
}
file.close();
printf("--------我是分隔符--------\n\n输入任意字符继续");
cin>>c;
}
bool op(void){
int cz;
system("cls");
printf("\n现在要作何操作?\n1.新建OC\n2.编辑已有OC\n3.查看已有OC\n输入其他关闭程序\n\n");
cin>>cz;
switch(cz){
case 1:{
CreatOC();
return 0;
break;
}case 2:{
printf("功能开发中…");
return 0;
break;
}case 3:{
Show();
return 0;
break;
}default:{
printf("再见");
return 1;
}
}
return 0;
}
int main(){
printf("欢迎使用OC编辑器!\n");
while(1){
if(op())return 0;
}
return 0;
}
怎么存多于一个oc