zoukankan      html  css  js  c++  java
  • c++ ios_base类

     ios_base is  Base class with type-independent members for the standard stream classes(ios);

    其中有一个成员函数

    ios_base::flags 用来控制流的格式。

    fmtflags flags ( ) const;  
    fmtflags flags ( fmtflags fmtfl );
    Get/set format flags
    The first syntax returns the current set of format flags set for the stream.
    The second syntax sets a new set of format flags for the stream, returning its former value.

    中的参数类型public member type ,ios_base::fmtflags 是Type for stream format flags;
     有很多字段 ,
    如  showbase,展示是几进制
     uppercase
    
    
    numerical base
    (basefield)
    dec read/write integral values using decimal base format.
    hex read/write integral values using hexadecimal base format.
    oct read/write integral values using octal base format.
    float format 
    (floatfield)
    fixed write floating point values in fixed-point notation.
    scientific write floating-point values in scientific notation.
    参考http://www.cplusplus.com/reference/iostream/ios_base/fmtflags/
    示例程序:
    
    
    // modify flags
    #include <iostream>
    using namespace std;

    int main () {
    cout.flags ( ios::right | ios::hex | ios::showbase );
    cout.width (10);
    cout << 100;
    return 0;
    }
    0x64
    This simple example sets some format flags for cout that affect the latter insertion operation by printing the value in hexadecimal base format (0x64) padded right as in a field ten spaces long:影响后来的流插入符。

    还可以这么写,用操作符来进行控制:
    #include <iostream>
    #include <iomanip>
    using namespace std;

    int main () {
    cout << hex << setiosflags (ios_base::showbase | ios_base::uppercase);
    cout << 100 << endl;
    return 0;
    }
    0x64
    这里setiosflags是个manipulator。

    setiosflags(ios::XXX)可以直接写成XXX。 如:cout<<setiosflags(ios::flxed)   cout<<fixed


    
    




     



     

  • 相关阅读:
    PHP 中各种命名规则的总结
    Linux 下安装mysql 8.0.11(CentOS 7.4 系统)
    常用端口号(转)
    Centos7 FPM 安装mysql8
    windows 下升级安装mysql8,与旧版本5.6共存
    【Eclipse】修改项目访问名称
    【Eclipse】报错提示删掉@Override
    【霓虹语】バスの火事
    【博客园】使用ifream的两种方法
    【Eclipse】调试java程序的九个技巧
  • 原文地址:https://www.cnblogs.com/youxin/p/2433868.html
Copyright © 2011-2022 走看看