gpt4 book ai didi

c++ - 为什么 (foobar>>x) 优于 (!foobar.eof() )

转载 作者:可可西里 更新时间:2023-11-01 16:31:13 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Why is iostream::eof inside a loop condition considered wrong?
eof() bad practice?

我的老师说我们不应该使用 EOF 来读取文本文件或二进制文件信息,而应该使用 (afile>>x)。他没有解释为什么,谁能给我解释一下。有人能解释一下这两种不同的阅读方法有什么区别吗

//Assuming declaration 
//ifstream foobar



( ! foobar.eof() )
{
foobar>>x; // This is discouraged by my teacher

}


while (foobar>>x)
{
//This is encouraged by my teacher

}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com