Namespaces
Variants

std::basic_ios<CharT,Traits>::operator bool

From cppreference.com
 
 
Input/output library
I/O manipulators
Print functions (C++23)
C-style I/O
Buffers
(deprecated in C++98)(removed in C++26)
Streams
Abstractions
File I/O
String I/O
Array I/O
(deprecated in C++98)(removed in C++26)
(deprecated in C++98)(removed in C++26)
(deprecated in C++98)(removed in C++26)
Synchronized Output
Types
Error category interface
(C++11)
 
 
operator /* unspecified-boolean-type */() const;
(1) (until C++11)
explicit operator bool() const;
(2) (since C++11)

Checks whether the stream has no errors.

1) Returns a value that evaluates to false in a boolean context if fail() returns true, otherwise returns a value that evaluates to true in a boolean context.
2) Returns true if the stream has no errors and is ready for I/O operations. Specifically, returns !fail().

This operator makes it possible to use streams and functions that return references to streams as loop conditions, resulting in the idiomatic C++ input loops such as while (stream >> value) {...} or while (std::getline(stream, string)) {...}. Such loops execute the loop's body only if the input operation succeeded.

Parameters

(none)

Return value

1) A value that evaluates to true in a boolean context if the stream has no errors, a value that evaluates to