c++ - getline() 如何在 while 循环条件中评估为 true 或 false?

标签 c++

例如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,其他状态如 eoffail 将评估为 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/

相关文章:

c++ - 不能反转运算符顺序

c++ - 错误 : export ordinal too large: 104116

具有两个 GLfloats 作为对的 C++11 vector 无法统一初始化

c# - 用于 P/Invoke 访问的引脚数据

c++ - 一个函数中的局部变量更改导致不相关的函数,C++

c++ - 如何从时间戳间隔获取天数列表

c++ - 类中析构函数定义的 Collect2 错误

c++ - 对 Class::Function() C++ 的 undefined reference

android - Android 应用程序 (NDK) 的 poppler 库可以代替 xpdf 吗?

c++ - 在运行时创建具有唯一函数指针的函数