std::showpos, std::noshowpos
来自cppreference.com
| 在标头 <ios> 定义
|
||
| |
(1) | |
| |
(2) | |
启用或禁用非负整数输出中的正号 '+' 的显示。在输入上无效果。
1) 如同用调用
str.setf(std::ios_base::showpos) 启用流 str 中的 showpos 标志。2) 如同用调用
str.unsetf(std::ios_base::showpos) 禁用流 str 中的 showpos 标志。这是一个 I/O 操纵符,可用如 out << std::showpos 的表达式对任何 std::basic_ostream 类型的 out 或用如 in >> std::showpos 的表达式对任何 std::basic_istream 类型的 in 调用。
参数
| str | - | 到 I/O 流的引用 |
返回值
str(到操纵后的流的引用)。
示例
运行此代码
#include <iostream>
int main()
{
std::cout
<< "showpos: " << std::showpos << 42 << ' ' << 3.14 << ' ' << 0 << '\n'
<< "noshowpos: " << std::noshowpos << 42 << ' ' << 3.14 << ' ' << 0 << '\n';
}
输出:
showpos: +42 +3.14 +0
noshowpos: 42 3.14 0
参阅
| 清除指定的 ios_base 标志 (函数) | |
| 设置指定的 ios_base 标志 (函数) |