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

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

功能: 

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

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

示例:

 1 #include <stdio.h>
 2 #include <tchar.h>
 3 #include <iostream>
 4 #include <iomanip>
 5 
 6 int _tmain(int argc, _TCHAR* argv[])
 7 {
 8      int a = 1;
 9      //输出:    1
10      std::cout<<std::setw(4)<<a<<std::endl;
11      //输出: ***1
12      std::cout<<std::setw(4)<<std::setfill('*')<<a<<std::endl;
13 
14      //输出:***12
15      int b = 2;
16      std::cout<<std::setw(4)<<std::setfill('*')<<a<<b<<std::endl;
17      system("pause");
18      return 0;
19 }

猜你喜欢

转载自www.cnblogs.com/luoluosha/p/11691760.html
std