📄 2-4.cpp
字号:
#include<iostream>
#include<string>
using std::cin;
using std::cout;
using std::endl;
using std::string;
int main()
{
cout<<"Please enter your first name: ";
string name;
cin>>name;
const string greeting="Hello, "+name+"!";
int pad;
cout<<"Please enter pad: ";
cin>>pad;
const int rows=pad*2+3;
const int mid=rows/2;
const string::size_type cols=greeting.size()+pad*2;
cout<<endl;
for(int r=0;r!=rows;++r)
{
if(r==mid)
{
const string temp(pad,' ');
cout<<"*"<<temp<<greeting<<temp<<"*"<<endl;
}
else if(r==0||r==rows-1)
{
const string first(cols,'*');
cout<<"*"<<first<<"*"<<endl;
}
else
{
const string second(cols,' ');
cout<<"*"<<second<<"*"<<endl;
}
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -