人较笨且记性不好,故记录在此.折叠代码打不开请F5.本博中很多是转载收录其他网友的文章(原文地址请见博文末尾),所有权为原作者所有!!!
此博客已不再更新和维护,欢迎关注我的github新博客

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: :: 管理 ::

头文件:
#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
 

posted on 2011-10-11 11:17  子坞  阅读(7762)  评论(0编辑  收藏  举报