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

功能:

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

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

示例:

View Code
#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;
}

【参考资料 感谢作者】
http://hi.baidu.com/kety19850518/blog/item/6d0e70c259fb6059b219a875.html
 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-22
  • 2022-03-08
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-03-07
  • 2022-01-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案