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为空,表达式求值为假,断言实现,输出错误信息,并退出程序。

转载于:https://www.cnblogs.com/wuyinfenghappy/p/7281956.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值