Here is the C ++ code that reads as many words from a given text file as possible until it encounters EOF.
string text;
fstream inputStream;
inputStream.open("filename.txt");
while (inputStream >> text)
cout << text << endl;
inputStream.close();
My question is:
- Which procedure is performed exactly to convert the condition of the while loop (i.e., inputStream → text) to boolean values (i.e., true or false)?
My own answer to the question:
- In my opinion, inputStream -> text should return another (file) input stream. The stream seems NULL when the EOF arrives. NULL can be defined as 0, which is equivalent to false.
Does my answer make sense? Even if my answer makes sense, such a conversion of InputStream to bool does not make me so convenient. :)
source
share