格式控制符

#include<iostream>
#include<iomanip>
using namespace std;
void main()
{
    int n,k;
    cout<<"请输入行数:"<<endl;
    cin>>k;
    for(n=1;n<=k;n++)
    {
        /*cout.width(20-n);
        cout.fill(' ');
        cout<<" ";
        cout.width(2*n-1);
        cout.fill('B');
        cout<<"B"<<endl;*///都可以
        cout<<setw(20-n)<<setfill(' ')<<" "<<setw(2*n-1)<<setfill('B')<<"B"<<endl;
    }
}

 

posted @ 2012-09-15 10:31  myth_HG  阅读(146)  评论(0编辑  收藏  举报