在线文档教程
C++
输入/输出 | Input/output

std::boolalpha

STD::boolalpha,std::noboolalpha

Defined in header
std::ios_base& boolalpha( std::ios_base& str (1)
std::ios_base& noboolalpha( std::ios_base& str (2)

1%29启用boolalpha溪流中的旗子str好像通过打电话str.setf(std::ios_base::boolalpha)

2%29禁用boolalpha溪流中的旗子str好像通过打电话str.unsetf(std::ios_base::boolalpha)

std::boolalpha是I/O操作器,因此可以用表达式调用它,如out << std::boolalpha对任何out类型std::basic_ostream或使用表达式,如in >> std::boolalpha对任何in类型std::basic_istream...

参数

str-reference to I/O stream

返回值

str%28操作后对流的引用%29。

二次

#include <sstream> #include <locale> #include <iostream> int main() { // boolalpha output std::cout << std::boolalpha << "boolalpha true: " << true << '\n' << "boolalpha false: " << false << '\n'; std::cout << std::noboolalpha << "noboolalpha true: " << true << '\n' << "noboolalpha false: " << false << '\n'; // booalpha parse bool b1, b2; std::istringstream is("true false" is >> std::boolalpha >> b1 >> b2; std::cout << '\"' << is.str() << "\" parsed as " << b1 << ' ' << b2 << '\n'; }

二次

产出:

二次

boolalpha true: true boolalpha false: false noboolalpha true: 1 noboolalpha false: 0 "true false" parsed as 1 0

二次

另见

resetiosflagsclears the specified ios_base flags (function)
setiosflagssets the specified ios_base flags (function)
do_truenamedo_falsename virtualprovides the string to use as the name of the boolean true and false (virtual protected member function of std::numpunct)

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/io/manip/boolalpha