原文:http://hi.baidu.com/xagzznuwlgbagpq/item/f49cee1b098996751109b536
头文件:
#include <iostream>
#include <iomanip>
using namespace std;
功能:
std::setw :表示占多少个字符,默认填充的字符为' '空格
std::setfill:设置std::setw将填充什么样的字符,如:std::setfill('*')
示例:

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