目录

boolalpha

描述 (Description)

它用于为str流设置boolalpha格式标志。 当设置boolalpha格式标志时,bool值通过其文本表示插入/提取:true或false,而不是整数值。

声明 (Declaration)

以下是std :: boolalpha函数的声明。

ios_base& boolalpha (ios_base& str);

参数 (Parameters)

str - 格式标志受影响的Stream对象。

返回值 (Return Value)

它返回Argument str。

异常 (Exceptions)

Basic guarantee - 如果抛出异常,str处于有效状态。

数据竞争 (Data races)

它修改了str。 对同一流对象的并发访问可能会导致数据争用。

例子 (Example)

在下面的例子中解释了std :: boolalpha的功能。

#include <iostream>     
int main () {
   bool b = true;
   std::cout << std::boolalpha << b << '\n';
   std::cout << std::noboolalpha << b << '\n';
   return 0;
}

让我们编译并运行上面的程序,这将产生以下结果 -

true
1
↑回到顶部↑
WIKI教程 @2018