目录

showpoint

描述 (Description)

它用于设置str流的showpoint格式标志。 设置showpoint格式标志时,始终为插入到流中的浮点值写入小数点(即使是小数部分为零的那些)。 在小数点之后,根据需要写入多个数字以匹配流的精度(如果有)。

声明 (Declaration)

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

ios_base& showpoint (ios_base& str);

参数 (Parameters)

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

返回值 (Return Value)

它返回Argument str。

异常 (Exceptions)

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

数据竞争 (Data races)

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

例子 (Example)

在下面的例子中解释了std :: showpoint函数。

#include <iostream>
int main () {
   double a = 30;
   double b = 10000.0;
   double pi = 3.1416;
   std::cout.precision (5);
   std::cout <<   std::showpoint << a << '\t' << b << '\t' << pi << '\n';
   std::cout << std::noshowpoint << a << '\t' << b << '\t' << pi << '\n';
   return 0;
}

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

30.000  10000.  3.1416
30      10000   3.1416
↑回到顶部↑
WIKI教程 @2018