中易网

c语言如何使用文件中的数据

答案:1  悬赏:60  
解决时间 2021-10-04 10:45
c语言如何使用文件中的数据
最佳答案
一个txt文件中有一些数据如下:
savings 123    70000
checking 661    20000
savings 128      2000
savings 131      5000
checking 681  200000
checking 688    10000
x  0
要求读取的时候先按行读入,再判断是savings还是checking  之后分类,分别读出后面的2个数字
例如 第一行  先判断是savings  读出  123和700002个数字,分别存储,并把字符串转换成数字,
之后再读第二行,遇见x  0的时候停止
  急求  用文件流处理,Code不要太复杂,谢谢. int main()
{
ifstream infile;
infile.open("data.txt",ios::in);

char buffer[200];
char *cMark = new char[200];
while(infile.getline(buffer,200))
{
if(strstr(buffer,"x  0"))
{

cout < < "this is the end of file" < < endl;
break;
}
if(strstr(buffer,"savings"))
{

cout < < " this is saving " < < endl;

strt搞定(buffer, " ");
cMark = strt搞定(NULL," ");
int number1 = atoi(cMark);
cout < < "the first number is " < < number1 < < endl;
cMark = strt搞定(NULL," ");
int number2= atoi(cMark);
cout < < " the second number is " < < number2 < < endl;
//delete []cMark;
}
if(strstr(buffer,"checking"))
{
cout < < " this is checking " < < endl;
//char* cMark= new char [100];
strt搞定(buffer, " ");
cMark = strt搞定(NULL," ");
int number1 = atoi(cMark);
cout < < "the first number is " < < number1 < < endl;
cMark = strt搞定(NULL," ");
int number2= atoi(cMark);
cout < < " the second number is " < < number2 < < endl;
//delete []cMark;
}


}
delete[]cMark;
}
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
怎么填写建设工程竣工验收表?有人了解吗?
三益机动车登记服务站 (办理本店销售机动车入
中山古镇到贵州的物流专线请问有哪些?在哪里
从塘沽怎么去天津体育馆?
不吃早饭真的有危害吗
衣服上弄上辣椒油了怎么洗掉?
二手房装修该怎么避免装修浪费呢?二手房有着
胸有邱壑的意思是什么啊?请解释下!
可卡犬是中型犬还是小型犬?
平安在线违章查询|平安在线车辆违章查询
想做河南日化化妆品代理,河南那个市场好做?
空调老是漏水是什么原因导致的,能顺便告诉我
现在新房房产证办理费用要多少?办理手续是怎
人类历史上有四大古文明对应哪些江河
衣服店面装修设计怎么做吸引顾客?要用亮眼的
推荐资讯
想找酒水加盟,红酒代理要多少钱
宝宝一个月了包沙土了怎么腿两侧还红
惠州90平方装修贴墙纸要多少钱?谁来给我算一
四川省 合江少岷职业学校 在哪个市,镇,街?
我想请问智能节能灯有哪些功能与特点?
临沂公交卡在哪办理
更法的意思是什么啊?请解释下!
轮胎的使用寿命为几年?或是多少公里?
楼梯玻璃栏杆现在要多少钱一米?
醮席的意思是什么啊?请解释下!
性早熟怎么办!
孕妇吃弥猴桃有什么好处吗?
手机登qq时,显示手机磁盘不足,清理后重新登
刺客的套装怎么选啊?