对文件流的操作问题

xqyangcsu xqyangcsu 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
各位大虾:
小弟很是迷惑阿!
下面这些代码:
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <iomanip>
#include <ctype.h>
#include <string>
using namespace std;
int main()
{
string name;
int price;
ifstream in;
in.open("merchantLog",ios::in);
if(!in)
{
cout<<"open file error"<<endl;
exit(1);
}

while(in)
{
in>>name;
cout<<setw(10)<<name;

in>>price;
cout<<setw(10)<<price<<endl;
}
in.close();
}

merchantLog文件中的内容:
box 78
pen 98
water 22
bread 9
wat 90
io 90
CD 99
DVD 990
book 45
Computer 8888
Mouse 100
mp3 999
coat 33
yxq 10000
d -1
为什么输出的结果中最后一行: d -1 输出两遍呢??
是不是流的缓冲区的问题呢?



...全文

相关推荐

评论 4
收藏 已收藏
分享
返回顶部
xqyangcsu
C++ 语言 65,214 成员 250,514 内容