对文件流的操作问题
各位大虾:
小弟很是迷惑阿!
下面这些代码:
#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 输出两遍呢??
是不是流的缓冲区的问题呢?