C++ 文件读取问题

苦楚涩 2009-03-21 12:34:25
C++ 文件读取有问题,帮帮忙啊,急!谢啦!
...全文
113 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
bbb332 2009-03-21
  • 打赏
  • 举报
回复
vincent_1011 2009-03-21
  • 打赏
  • 举报
回复
-_0,围观
  • 打赏
  • 举报
回复
什么问题?代码?
苦楚涩 2009-03-21
  • 打赏
  • 举报
回复
#include <cstdlib>
#include <iostream>
#include<string>
#include<vector>
#include <fstream>
#include<algorithm>
#include <sstream>

using namespace std;
struct timesfor{
int a;
string b;
};
bool comp( const timesfor &a,const timesfor &b){
return a.a>b.a;
};
class accident{
private: string bianhao;
string chepaihao;
string name;
string sex;
string reason;
string time;
string place;
public:
accident(string a,string b,string c,string d,string e,string f,string g){
bianhao=a;
chepaihao=b;
name=c;
sex=d;
reason=e;
time=f;
place=g;
}
string getBH(){
return bianhao;
}
string getCPH(){
return chepaihao;
}
string getN(){
return name;
}
string getS(){
return sex;
}
string getR(){
return reason;
}
string getT(){
return time;
}
string getP(){
return place;
}
void setBH(string a){
bianhao=a;
}
void setCPH(string a){
chepaihao=a;
}
void setN(string a){
name=a;
}
void setS(string a){
sex=a;
}
void setR(string a){
reason=a;
}
void setT(string a){
time=a;
}
void setP(string a){
place=a;
}
void dis(){
cout<<getBH()<<getCPH()<<getN()<<getS()<<getR()<<getT()<<getP()<<endl;
}
};
int main(int argc, char *argv[])
{
vector<accident>total;
int selectnum;
string bianhao;
string chepaihao;
string name;
string sex;
string reason;
string time;
string place;
while(1){
fflush(stdin);
cin.clear();
fflush(stdout);
cout<<"1 录入信息"<<endl;
cout<<"2 删除信息"<<endl;
cout<<"3 修改信息"<<endl;
cout<<"4 显示信息"<<endl;
cout<<"5 查询信息"<<endl;
cout<<"6 统计信息"<<endl;
cout<<"7 保存信息"<<endl;
cout<<"8 读取信息"<<endl;
cout<<"9 退出系统"<<endl;
cout<<"选择操作,输入前面的数字:";
cin>>selectnum;
switch(selectnum){
case 1:{
cout<<"输入顺序按照编号、车牌号、车主姓名、性别、违章情况、违章时间、地点"<<endl;
cin>>bianhao>>chepaihao>>name>>sex>>reason>>time>>place;
accident accid(bianhao,chepaihao,name,sex,reason,time,place);
total.push_back(accid);
for(int i=0;i<total.size();i++){
total[i].dis();
}
break;
};
case 2:{
if(total.size()!=0)
{
cout<<"全部删除(y/Y)删除单个(任意键)";
string deljud;
cin>>deljud;
if(deljud=="y")total.clear();
else{
cout<<"请输入所要修改信息的编号:";
string delnum;
cin>>delnum;
for(int i=0;i<total.size();i++){
if(total[i].getBH()==delnum){
accident* delacc=&total[i];
total.erase(delacc);
}
}
cout<<"删除成功!"<<endl;
}
}
else
cout<<"数据为空,请输入新数据!"<<endl;
break;
};
case 3:{
if(total.size()!=0)
{
cout<<"请输入所要修改信息的编号:";
string modnum;
cin>>modnum;
bool modfind=false;
for(int i=0;i<total.size();i++){
if(total[i].getBH()==modnum){
modfind=true;
cout<<"输入顺序按照编号、车牌号、车主姓名、性别、违章情况、违章时间、地点"<<endl;
cin>>bianhao>>chepaihao>>name>>sex>>reason>>time>>place;
accident accid(bianhao,chepaihao,name,sex,reason,time,place);
total[i]=accid;
}
cout<<"修改成功!"<<endl;
}
if(!modfind)cout<<"没有您要找的记录!"<<endl;
}
else
cout<<"数据为空,请输入新数据!"<<endl;
break;
};
case 4:{
if(total.size()!=0)
{
for(int i=0;i<total.size();i++)
{
total[i].dis();
}
}
else
cout<<"数据为空,请输入新数据!"<<endl;
break;
};
苦楚涩 2009-03-21
  • 打赏
  • 举报
回复
代码太长,分着给啊。
苦楚涩 2009-03-21
  • 打赏
  • 举报
回复
代码太长,分着给啊。
matrix_chen 2009-03-21
  • 打赏
  • 举报
回复
什么都没给?
Qlaiaqu 2009-03-21
  • 打赏
  • 举报
回复
ifstream ifi("address")'
if(ifi) 判断文件是否打开
eof 判断是否到文件尾
bad判断是不是系统级别错误,不可恢复
fail判断是不是一般的错误,可以恢复
pengzhixi 2009-03-21
  • 打赏
  • 举报
回复
唉,又一个急得什么都忘了的
wolflion 2009-03-21
  • 打赏
  • 举报
回复
没办法帮你啦。
cheidtf 2009-03-21
  • 打赏
  • 举报
回复
问题都没有看到啊!
lzy340623339 2009-03-21
  • 打赏
  • 举报
回复
lz还是把代码贴出来先吧
hylove9494 2009-03-21
  • 打赏
  • 举报
回复
说的具体点!!!
毛员外 2009-03-21
  • 打赏
  • 举报
回复
代码都没得哒

65,211

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧