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


    
    




     



     

  • 相关阅读:
    Python字符串
    MySQL触发器
    MySQL 1418报错解决办法
    数据库下载
    补码与反码
    二、八、十六进制之间的转换
    this 指向
    作用域 var 词法分析 arguments
    事件绑定的3种方式
    清浮动方法小结
  • 原文地址:https://www.cnblogs.com/youxin/p/2433868.html
Copyright © 2011-2022 走看看