std::noshowbase
STD::展示基础,STD::nohowbase
Defined in header | | |
---|---|---|
std::ios_base& showbase( std::ios_base& str | (1) | |
std::ios_base& noshowbase( std::ios_base& str | (2) | |
1%29启用showbase
溪流中的旗子str
好像通过打电话str.setf(
std::ios_base::showbase
)
...
2%29禁用showbase
溪流中的旗子str
好像通过打电话str.unsetf(
std::ios_base::showbase
)
...
这是一个I/O操作程序,可以用表达式调用它,如out << std::showbase对任何out类型std::basic_ostream或使用表达式,如in >> std::showbase对任何in类型std::basic_istream...
大showbase
标志影响整数输出%28的行为(参见std::num_put::put
%29,货币投入%28见std::money_get::get
%29和货币产出%28见std::money_put::put
29%。
参数
str | - | reference to I/O stream |
---|
返回值
str
%28操作后对流的引用%29。
注记
如std::num_put::put
,整数输出中的显示基标志的作用类似于std::printf
,这意味着数字基前缀是不
在输出值为零时添加。
例
二次
#include <sstream>
#include <locale>
#include <iostream>
#include <iomanip>
int main()
{
// showbase affects the output of octals and hexadecimals
std::cout << std::hex
<< "showbase: " << std::showbase << 42 << '\n'
<< "noshowbase: " << std::noshowbase << 42 << '\n';
// and both input and output of monetary values
std::locale::global(std::locale("en_US.utf8")
long double val = 0;
std::istringstream is("3.14"
is >> std::showbase >> std::get_money(val
std::cout << "With showbase, parsing 3.14 as money gives " << val << '\n';
is.seekg(0
is >> std::noshowbase >> std::get_money(val
std::cout << "Without showbase, parsing 3.14 as money gives " << val << '\n';
}
二次
产出:
二次
showbase: 0x2a
noshowbase: 2a
With showbase, parsing 3.14 as money gives 0
Without showbase, parsing 3.14 as money gives 314
二次
另见
resetiosflags | clears the specified ios_base flags (function) |
---|---|
setiosflags | sets the specified ios_base flags (function) |
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。