showpos
描述 (Description)
它用于设置str流的showpos格式标志。 当设置showpos格式标志时,加号(+)在插入流中的每个非负数值(包括零)之前。
声明 (Declaration)
以下是std :: showpos函数的声明。
ios_base& showpos (ios_base& str);
参数 (Parameters)
str - 格式标志受影响的Stream对象。
返回值 (Return Value)
它返回Argument str。
异常 (Exceptions)
Basic guarantee - 如果抛出异常,str处于有效状态。
数据竞争 (Data races)
它修改了str。 对同一流对象的并发访问可能会导致数据争用。
例子 (Example)
在下面的例子中解释了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