练习3.2
#include <iostream>
using namespace std;
int main()
{
string line;
//标准输入一次读取一行
/*
while(getline(cin, line))
cout << line << endl;
*/
//一次只能读取一个单词,cin如果读取到换行或者空格就会停止读取
string word;
cin >> word;
cout << word << endl;
return 0;
}
练习3.3
string类的输入运算符遇到空白字符,停止将字符读取到string类变量中,在开头的空白将会被忽略;
getline会吸收空白字符,并将空白字符保存在string类变量中
练习3.4
string s1, s2;
getline(cin, s1);
getline(cin, s2);
/*
if(s1 == s2)
cout << s1 << "equal" << s2 << endl;
else if(s1 > s2)
cout << s1 << endl;
else
cout << s2 << endl;
*/
if(s1.length() == s2.length())
cout << s1 << " lenth equal " << s2 << endl;
else if(s1 > s2)
cout << s1 << endl;
else
cout << s2 << endl;
练习3.5
string s1, s2;
getline(cin, s1);
getline(cin, s2);
s2 += s1;
cout << s2 << endl;
//修改的
string s1, s2;
cin >> s1 >> s2;
s1 += " " + s2;
cout << s1 << endl;