c++ primer 6.5.3节练习答案

练习6.47

打开调试器:

 1 void print_vector(const vector<string> &str)
 2 {
 3     #ifndef NDEBUG
 4     cerr << "the sizeof vector:" << str.size() << endl;
 5     #endif // !NDEBUG
 6     for (auto c : str)
 7             cout << c << endl;
 8 }
 9 int main()
10 {
11     vector <string> str1{ "hello","world","i","am","superman" };
12     print_vector(str1);
13     system("pause");
14     return 0;
15 }

关闭调试器

 1 void print_vector(const vector<string> &str)
 2 {
 3     #define NDEBUG
 4     #ifndef NDEBUG
 5     cerr << "the sizeof vector:" << str.size() << endl;
 6     #endif // !NDEBUG
 7     for (auto c : str)
 8             cout << c << endl;
 9 }
10 int main()
11 {
12     vector <string> str1{ "hello","world","i","am","superman" };
13     print_vector(str1);
14     system("pause");
15     return 0;
16 }

练习6.48

不合理,当不再输入,或者s = sought时,此时cin为空,表达式求值为假,断言实现,输出错误信息,并退出程序。

posted @ 2017-08-03 21:25  五月份小姐  阅读(292)  评论(0编辑  收藏  举报