std_setw(size)与std_setfill(char)

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

功能:

std::setw :需要填充多少个字符,默认填充的字符为’ ‘空格
std::setfill:设置 std::setw 将填充什么样的字符,如:std::setfill(‘*‘)

头文件:

#include

#include
using namespace std;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

#include <iostream>
#include <iomanip>

int _tmain(int argc, _TCHAR* argv[])
{
int a = 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;
}