istream的operator>>用于读取数据,并返回对istream的引用。
例如,
istream& operator>> (bool& val);
但是当 istream 在条件语句中使用时,它是如何转换为 bool 值的呢?
例如:
ifstream ifs(.....); // open the file
istream &is = (istream&)ifs;
char c;
if(is >> c) // how the istream is been evaluated into as bool
{
// character read
}
有人能解释一下在条件表达式中它是如何转换为布尔值的吗?
ifstream
是从istream
派生的吗? - John