• 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


    
    




     



     

  • 相关阅读:
    用循环链表求解约瑟夫问题
    Nim游戏变种——取纽扣游戏
    POJ-2726-Holiday Hotel
    常用排序算法总结(二)
    常用排序算法总结(一)
    找出数组中出现次数最多的那个数——主元素问题
    C99新特性:变长数组(VLA)
    linux tftp配置 (Ubuntu18.04)
    Ubuntu 18.04安装Samba服务器及配置
    记录学习Linux遇到的问题
  • 原文地址:https://www.cnblogs.com/youxin/p/2433868.html
Copyright © 2020-2023  润新知