首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::showbase

Defined in header <ios>

?

?

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::put29%。

参数

str

-

reference to I/O stream

返回值

str%28操作后对流的引用%29。

注记

std::num_put::put,整数输出中的显示基标志的作用类似于std::printf,这意味着数字基前缀是在输出值为零时添加。

二次

代码语言:javascript
复制
#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';
}

二次

产出:

二次

代码语言:javascript
复制
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)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com