- 论坛徽章:
- 0
|
本帖最后由 confide423 于 2011-11-29 21:22 编辑
#include <iostream>
#include <string>
using std::cin;
using std::cout;
using std::endl;
using std::string;
int main(int argc, char *argv[])
{
cout<<"Please enter your first name: ";
string name;
cin>>name;
const string greeting="Hello, "+name+"!";
const int pad=1;
const int rows=pad*2+2+3;
const string::size_type cols=greeting.size()+pad*2+2;
cout<<endl;
for(int r=0;r!=rows;r++)
{
string::size_type c=0;
while(c!=cols)
{
if(r==pad+1)
{
cout<<greeting;
c+=greeting.size();
}
else if(r==0|r==rows-1||c==0||c==cols-1)
cout<<"*";
else
cout<<" ";
c++;
}
cout<<endl;
}
return 0;
}
我想打印类似下面的结果:
******************
* *
* Hello,Frank! *
* *
****************** |
|