社区
C++ 语言
帖子详情
C++ 文件读取问题
苦楚涩
2009-03-21 12:34:25
C++ 文件读取有问题,帮帮忙啊,急!谢啦!
...全文
113
14
打赏
收藏
C++ 文件读取问题
C++ 文件读取有问题,帮帮忙啊,急!谢啦!
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
14 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
bbb332
2009-03-21
打赏
举报
回复
?
vincent_1011
2009-03-21
打赏
举报
回复
-_0,围观
猫已经找不回了
2009-03-21
打赏
举报
回复
什么问题?代码?
苦楚涩
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
打赏
举报
回复
代码都没得哒
c++
文件
读取
最后一行
读取
两次的
问题
c++
文件
读取
最后一行
读取
两次的
问题
新人博客。本来记笔记用word,写博客查阅更方便,资料也不容易丢失还能与人交流,也就转战博客了。在做
c++
文件
流的题目时要求将20个数据从
文件
中
读取
到一个长度为20的向量中,我本来是这么写的: i=0; while(in.eof()==false) { if(in.bad()==false&&in.fail()==false)
C++
读取
BIN
文件
的一些
问题
程序要求
读取
一个ARM的BIN
文件
,需要获取每一个字节,写了一个函数测试一下:
文件
: 由于不熟悉,弄出了很多
问题
。相关
问题
如下: 1 BIN
文件
(大部分见https://www.cnblogs.com/pengwangguoyh/articles/3223072.html) BIN
文件
不以ASCII码存放数据,它将内存中数据存储形式不加转换地传送到磁盘
文件
,因此它又称为...
解决
c++
ifstream in对象
读取
文件
总多读一次
问题
先上源码 #include <iostream> #include <fstream> #include "xitong.h" using namespace std; int main(int argc, char const *argv[]) { string a, b, c; ifstream in; int cnt = 0; in.o...
C++
中常见的
文件
读取
结尾
问题
在使用C/
C++
读
文件
的时候,一定都使用过eof()这个函数来判断
文件
是否为空或者是否读到
文件
结尾了,也会在使用这个函数的过程中遇到一些
问题
,如不能准确的判断是否为空或者是否到了
文件
尾,以至于有些人可能还会怀疑这个函数是不是本身在设计上就有
问题
。先来看看如下这段代码:#include stream>#include fstream>using namespace std;int main(
C++
重复
读取
文件
最后一行
问题
&&解决
#include <iostream> #include <string> #include <fstream> using namespace std; int main(int argc, char *argv[]) { ifstream in_file("test.txt", ios::in); if (!in_file) exit(-1); st...
C++ 语言
65,211
社区成员
250,514
社区内容
发帖
与我相关
我的任务
C++ 语言
C++ 语言相关问题讨论,技术干货分享,前沿动态等
复制链接
扫一扫
分享
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++
技术论坛(原bbs)
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
请不要发布与C++技术无关的贴子
请不要发布与技术无关的招聘、广告的帖子
请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下
试试用AI创作助手写篇文章吧
+ 用AI写文章