今天看《标准程序库》,有一句是这么说的:
cout << boolalpha;
于是就找msdn:
Specifies that variables of type bool appear as true or false in the stream.
意思就是将bool类型输出true或者false 而不是1或者0
样例:
// ios_boolalpha.cpp
// compile with: /EHsc
#include <iostream>
int main( )
{
using namespace std;
bool b = true;
cout << b << endl;
boolalpha( cout );
cout << b << endl;
noboolalpha( cout );
cout << b << endl;
cout << boolalpha << b << endl;
}
输出:
1
true
1
true