Choice
Choice

Reputation: 85

C++ attempting to read a char when EOF is reached

ifstream inputFile("blah.txt");
char c;
inputFile.read((char *)(&c), 1);

Let's say at the read, the file has already reached the EOF.
What value ends up in c?

Upvotes: 0

Views: 89

Answers (1)

ly000
ly000

Reputation: 363

Characters are extracted and stored until any of the following conditions occurs: ... end of file condition occurs on the input sequence ...

Read more at: http://en.cppreference.com/w/cpp/io/basic_istream/read

So your char will contain the same value as before.

Upvotes: 2

Related Questions