C++ ios 庫 - Noshowpos 函式



描述

它用於設定 str 流的 showpos 格式標誌。當設定 showpos 格式標誌時,一個加號 (+) 會出現在插入到流中的每個非負數值(包括零)之前。

宣告

以下是 std::showpos 函式的宣告。

ios_base& showpos (ios_base& str);

引數

str − 受格式標誌影響的流物件。

返回值

它返回引數 str。

異常

基本保證 − 如果丟擲異常,則 str 處於有效狀態。

資料競爭

它修改了 str。對同一流物件的併發訪問可能會導致資料競爭。

示例

下面的示例說明了 std::showpos 函式。

#include <iostream>

int main () {
   int p = 1;
   int z = 0;
   int n = -1;
   std::cout << std::showpos   << p << '\t' << z << '\t' << n << '\n';
   std::cout << std::noshowpos << p << '\t' << z << '\t' << n << '\n';
   return 0;
}

讓我們編譯並執行以上程式,這將產生以下結果:

+1      +0      -1
1       0       -1
ios.htm
廣告