std::setw(size)与std::setfill(char)

来源:互联网 发布:java中static什么意思 编辑:程序博客网 时间:2024/06/09 05:40
#include <stdio.h>#include <tchar.h>#include <iostream>#include <iomanip>int _tmain(int argc, _TCHAR* argv[]){     int a = 1;     //输出:    1     std::cout<<std::setw(4)<<a<<std::endl;     //输出: ***1     std::cout<<std::setw(4)<<std::setfill('*')<<a<<std::endl;     //输出:***12     int b = 2;     std::cout<<std::setw(4)<<std::setfill('*')<<a<<b<<std::endl;     system("pause");     return 0;}


头文件:
#include <iostream>
#include <iomanip>
using namespace std;

功能:

std::setw :需要填充多少个字符,默认填充的字符为' '空格

std::setfill:设置std::setw将填充什么样的字符,如:std::setfill('*')

 

原创粉丝点击