c++ primer 5.4.4节练习答案

练习5.18

a)循环体少了花括号;

b)不允许在条件部分定义变量;

c)condition使用的变量必须定义在循环体之外;

练习5.19

 1 int main()
 2 {
 3     string str1, str2;
 4     int i;
 5     do
 6     {
 7         cout << "please enter two string:";
 8         if (cin >> str1 >> str2)
 9         {
10             if (str1.size() < str2.size())
11                 cout << str1 << endl;
12             else
13                 cout << str2 << endl;
14         }
15         cin >> i;
16     } while (i != 0);
17     system("pause");
18     return 0;
19 }

 

posted @ 2017-08-01 20:58  五月份小姐  阅读(422)  评论(0)    收藏  举报