當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


C++ ios showpoint用法及代碼示例


描述

它用於設置 str 流的 showpoint 格式標誌。當設置了 showpoint 格式標誌時,總是為插入到流中的浮點值寫入小數點(即使對於小數部分為零的浮點值)。在小數點之後,根據需要寫入盡可能多的數字以匹配為流(如果有)設置的精度。

聲明

以下是 std::showpoint 函數的聲明。

ios_base& showpoint (ios_base& str);

參數

str− 格式標誌受到影響的流對象。

返回值

它返回參數 str。

異常

Basic guarantee- 如果拋出異常,則 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

相關用法


注:本文由純淨天空篩選整理自 C++ ios Library - Showpoint Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。