A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/reference/ios/basic_ios/operator_bool/ below:

public member function

<ios> <iostream>

std::basic_ios::operator bool
explicit operator bool() const;

Evaluate stream

Returns whether an error flag is set (either failbit or badbit).

Notice that this function does not return the same as member good, but the opposite of member fail.

The function returns a null pointer if at least one of these error flags is set, and some other value otherwise.

The function returns false if at least one of these error flags is set, and true otherwise.


Parameters none

Return Value

A

null pointer

if at least one of

failbit

or

badbit

is set. Some other value otherwise.



Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// evaluating a stream
#include <iostream>     // std::cerr
#include <fstream>      // std::ifstream

int main () {
  std::ifstream is;
  is.open ("test.txt");
  if (is) {
    // read file
  }
  else {
    std::cerr << "Error opening 'test.txt'\n";
  }
  return 0;
}

Data races Accesses the stream object.
Concurrent access to the same stream object may cause data races.

Exception safetyStrong guarantee: if an exception is thrown, there are no changes in the stream.

See also
basic_ios::fail
Check whether failbit or badbit is set (public member function)
basic_ios::operator!
Evaluate stream (not) (public member function)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4