开发者

How do iostream references evaluate to true/false

Example code:

#include <iostream>
#include <string>
#include <sstream>

using namespace std;

i开发者_高级运维nt main() {
    int num;
    stringstream ss("1");
    if (ss >> num) cout << "It was true\n";
    return 0;
}

How is "ss >> num" able to evaluate to a boolean value? Is there some operator that's been overloaded in stringstream? The STL says that the >> operator returns a reference to a stream.


Yes- the iostreams have an operator void* in C++03 and an explicit conversion to bool in C++11.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜