例如while(getline( , ))
这种条件什么时候为真/假,为什么用它们代替其他情境条件?
最佳答案
when is this kind of condition true/false
鉴于 documentation of std::getline()
它表示返回值是操作中涉及的流的 std::istream
引用,该流如何评估为 true
或 假
。
这是使用重载的 cast operator to bool
完成的继承自 std::ios
类。
此类定义指示当前流状态的状态标志,只有当流状态为 good
时才会评估 true
,其他状态如 eof
或 fail
将评估为 false
。
and why are they used instead of other situational conditions?
高度相关的问答:Why is iostream::eof inside a loop condition considered wrong?
关于c++ - getline() 如何在 while 循环条件中评估为 true 或 false?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51128037/