函式
<ios> <iostream>

std::noshowpos

ios_base& noshowpos (ios_base& str);
不顯示正號
清除str流的showpos格式標誌。

當未設定showpos格式標誌時,在插入str的非負值前不顯示加號(+)。

此標誌可透過showpos操縱符設定,該操縱符強制在插入流的每個非負數值(包括零)前寫入加號(+)。

對於標準流,showpos標誌在初始化時為未設定

引數

str
格式標誌受影響的流物件。
因為此函式是一個操縱符,它被設計為在不帶引數的情況下,與流上的插入 (<<) 和提取 (>>) 操作結合使用(見下例)。

返回值

引數 str

示例

1
2
3
4
5
6
7
8
9
10
11
// modify showpos flag
#include <iostream>     // std::cout, std::showpos, std::noshowpos

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


資料競爭

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

異常安全

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

另見