2011-08-26 18 views
2

示例代碼:如何iostream的引用計算爲真/假

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

using namespace std; 

int main() { 
    int num; 
    stringstream ss("1"); 
    if (ss >> num) cout << "It was true\n"; 
    return 0; 
} 

如何「SS >> NUM」能夠評估一個布爾值?是否有一些運算符在stringstream中被超載? STL表示>>操作符返回對流的引用。

回答

4

是 - iostreams在C++ 03中有operator void*,在C++ 11中有明確的轉換爲bool

+0

哇,快...... –