A RetroSearch Logo

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

Search Query:

Showing content from https://cplusplus.com/basic_ios::eof below:

public member function

<ios> <iostream>

std::basic_ios::eof

Check whether eofbit is set

Returns true if the eofbit error state flag is set for the stream.

This flag is set by all standard input operations when the End-of-File is reached in the sequence associated with the stream.

Note that the value returned by this function depends on the last operation performed on the stream (and not on the next).

Operations that attempt to read at the End-of-File fail, and thus both the eofbit and the failbit end up set. This function can be used to check whether the failure is due to reaching the End-of-File or to some other reason.



Parameters none

Return Valuetrue if the stream's eofbit error state flag is set (which signals that the End-of-File has been reached by the last input operation).
false otherwise.

Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// ios::eof example
#include <iostream>     // std::cout
#include <fstream>      // std::ifstream

int main () {

  std::ifstream is("example.txt");   // open file

  char c;
  while (is.get(c))                  // loop getting single characters
    std::cout << c;

  if (is.eof())                      // check for EOF
    std::cout << "[EoF reached]\n";
  else
    std::cout << "[error reading]\n";

  is.close();                        // close file

  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::good
Check whether state of stream is good (public member function)
basic_ios::fail
Check whether failbit or badbit is set (public member function)
basic_ios::bad
Check whether badbit is set (public member function)
basic_ios::rdstate
Get error state flags (public member function)
basic_ios::clear
Set error state flags (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