使用软件为Code::blocks
1)
string str;
while(cin>>str)
cout<<str<<endl;
2) string rsp;
do {
cout<<"please enter two values:";
int val1=0,val2=0;
cin>>val1>>val2;
cout<<"The sum of val1 and val2 is "<<val1+val2<<endl;
cout<<"More? Enter 'yes' or 'no' :";
cin>>rsp;
}while(!rsp.empty()&&rsp[0]!='n');
可以通过ctrl+z再按回车键表示停止输入,直接回车是不可以的。
cin>>str遇到空白为一个字符串。