c++做了程序,通过结构体把学号姓名等存入txt文档,然后怎样输入学号显示txt的姓名课程等信息
怎样实现呢?代码还在设计阶段:输入时候的代码:voidSystem::tianjia(){system("cls");fstreamin1;in1.open("C:\\U...
怎样实现呢?
代码还在设计阶段:
输入时候的代码:
void System:: tianjia()
{ system("cls");
fstream in1;
in1.open("C:\\Users\\Administrator\\Desktop\\考勤管理系统\\dat.txt",ios::out|ios::app);
int i;
int m;
cout<<"请输入学生学号:"<<endl;
cin>>i;
m=i;
CSystem[i].ID=m;
in1<<CSystem[i].ID;
//in1<<" ";
cout<<"请输入学生姓名:"<<endl;
cin>>CSystem[i].Name;
in1<<CSystem[i].Name;
//in1<<" ";
cout<<"请输入学生旷课课程:"<<endl;
cin>>CSystem[i].kecheng;
in1<<CSystem[i].kecheng;
//in1<<" ";
cout<<"请输入学生旷课课时数:"<<endl;
cin>>CSystem[i].Num;
in1<<CSystem[i].Num;
//in1<<" ";
cout<<"请输入学生旷课时间:"<<endl;
cin>>CSystem[i].Time;
in1<<CSystem[i].Time;
in1.close();
system("cls");
查询函数:
cout<<"请输入查询的学号:";
int i;
cin>>i;
int q=0;
ifstream out1;
out1.open("C:\\Users\\Administrator\\Desktop\\考勤管理系统\\dat.txt",ios::in) ;
while(!out1.eof())
{out1>>CSystem[q].ID;
out1>>CSystem[q].Name;
out1>>CSystem[q].kecheng;
out1>>CSystem[q].Num;
out1>>CSystem[q].Time;
q++;
}
out1.close();
cout<<"学号 " <<"姓名 " <<"课程 " <<"次数 " <<"时间 " <<endl;
cout<<CSystem[i].ID<<" " <<CSystem[i].Name<<" " <<CSystem[i].kecheng<<" " <<CSystem[i].Num<<" " <<CSystem[i].Time;
到底怎么做呢? 展开
代码还在设计阶段:
输入时候的代码:
void System:: tianjia()
{ system("cls");
fstream in1;
in1.open("C:\\Users\\Administrator\\Desktop\\考勤管理系统\\dat.txt",ios::out|ios::app);
int i;
int m;
cout<<"请输入学生学号:"<<endl;
cin>>i;
m=i;
CSystem[i].ID=m;
in1<<CSystem[i].ID;
//in1<<" ";
cout<<"请输入学生姓名:"<<endl;
cin>>CSystem[i].Name;
in1<<CSystem[i].Name;
//in1<<" ";
cout<<"请输入学生旷课课程:"<<endl;
cin>>CSystem[i].kecheng;
in1<<CSystem[i].kecheng;
//in1<<" ";
cout<<"请输入学生旷课课时数:"<<endl;
cin>>CSystem[i].Num;
in1<<CSystem[i].Num;
//in1<<" ";
cout<<"请输入学生旷课时间:"<<endl;
cin>>CSystem[i].Time;
in1<<CSystem[i].Time;
in1.close();
system("cls");
查询函数:
cout<<"请输入查询的学号:";
int i;
cin>>i;
int q=0;
ifstream out1;
out1.open("C:\\Users\\Administrator\\Desktop\\考勤管理系统\\dat.txt",ios::in) ;
while(!out1.eof())
{out1>>CSystem[q].ID;
out1>>CSystem[q].Name;
out1>>CSystem[q].kecheng;
out1>>CSystem[q].Num;
out1>>CSystem[q].Time;
q++;
}
out1.close();
cout<<"学号 " <<"姓名 " <<"课程 " <<"次数 " <<"时间 " <<endl;
cout<<CSystem[i].ID<<" " <<CSystem[i].Name<<" " <<CSystem[i].kecheng<<" " <<CSystem[i].Num<<" " <<CSystem[i].Time;
到底怎么做呢? 展开
2个回答
展开全部
假设txt是
number name class times time
number name class times time
number name class times time
number name class times time
匹配number,ok的话输出这一行
number name class times time
number name class times time
number name class times time
number name class times time
匹配number,ok的话输出这一行
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询