C++ ios 库 - Noshowpoint 函数



描述

它用于设置 str 流的 showpoint 格式标志。当设置 showpoint 格式标志时,对于插入到流中的浮点值(即使其小数部分为零),始终写入小数点。在小数点之后,将写入尽可能多的数字以匹配为流设置的精度(如有)。

声明

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

ios_base& showpoint (ios_base& str);

参数

str − 受影响的流对象的格式标志。

返回值

它返回参数 str。

异常

基本保证 − 如果抛出异常,str 处于有效状态。

数据竞争

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

示例

下面的例子解释了 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
ios.htm
广告