5.18
(a) do { // 加花括号
int v1, v2;
cout << "Please enter two numbers to sum:" ;
if (cin >> v1 >> v2)
cout << "Sum is: " << v1 + v2 << endl;
}while (cin);
(b) int ival;
do {
// . . .
} while (ival = get_response()); // 不能在这声明为int
(c) int ival = get_response();
do {
ival = get_response();
} while (ival); // 应该在花括号外声明ival
5.19
#include <iostream>
#include <string>
using namespace std;
int main()
{
while(true) {
cout << "输入2个string: ";
string str1, str2;
cin >> str1 >> str2;
cout << (str1 <= str2 ? str1 : str2) <<endl;
}
return 0;
}