From《Accelerated C++》P11——
需
cout输出字符串的练习,其结果如图:
代码如下:
#include<iostream>
#include<string>
using namespace std;
int main()
{
cout<<"please enter your first name:";
string name;
cin>>name;
const string sentences="hello,"+name;//1
const string spaces(sentences.size(),' ');//2
const string second='*'+spaces+'*';
const string first(second.size(),'*');
cout<<first<<endl;
cout<<second<<endl;
cout<<'*'<<sentences<<'*'<<endl;
cout<<second<<endl;
cout<<first<<endl;
return 0;
}
需