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

#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('*')

 

你可能感兴趣的:(std::setw(size)与std::setfill(char))