BZ易风

导航

 

字符输出

  • cout.flush() //刷新缓冲区 Linux下有效
  • cout.put() //向缓冲区写字符
  • cout.write() //从buffer中写num个字节到当前输出流中

cout.put()

 cout.write()

格式化输出

 

 

 实例:

void test02()
{
    int number = 99;
    cout.width(5);            //前置填充 一共5个字符,不够的话前面填充指定字符  ***99
    cout.fill('*');            //以指定字符填充
    cout.setf(ios::left);    // setf设置格式  ios::left左对齐,即后填充  99***
    cout.unsetf(ios::dec); // unsetf卸载  ios::dec十进制        99***
    cout.setf(ios::hex);    //设置        十六进制    63***
    cout.setf(ios::showbase);    //设置 强制输出整数基数(数字前缀 0 0x)         0x63*
    cout.unsetf(ios::hex);        //卸载 16进制    99***
    cout.setf(ios::oct);        //设置 8进制    0143*
    cout << number << endl;
}

控制符输出

实例:

 

需要引入iomanip

#include <iomanip>
void test03()
{
    int number = 99;
    cout << setw(10)        //字符长度 前填充
        <<setfill('*')        //填充
        << number
        << endl;
}

结果:

 

posted on 2021-08-25 16:37  BZ易风  阅读(60)  评论(0编辑  收藏  举报