函式
<ios> <iostream>

std::showpos

ios_base& showpos (ios_base& str);
顯示正號
str 流設定 showpos 格式標誌。

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

可以使用 noshowpos 操縱器取消設定此標誌。

對於標準流,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 處於有效狀態。

另見