【发布时间】:2011-03-29 01:29:35
【问题描述】:
我有这个文本示例
Ahmed 10
kmal 5
doola 6
我正在使用这段代码来阅读它
if (myfile.is_open())
{
while ( myfile.good() )
{
myfile >> name;
myfile >> phone;
cout << name <<" "<<phone<<endl;
}
myfile.close();
}
我得到这个输出
Ahmed 10
kmal 5
doola 6
doola 6
为什么这段代码读取了最后一行两次?
【问题讨论】:
-
试试
while (myfile.good() && !myfile.eof())。 -
查看如何正确使用流标志:stackoverflow.com/questions/4258887/…
标签: c++