Cpp_Primer_Answers icon indicating copy to clipboard operation
Cpp_Primer_Answers copied to clipboard

《C++ Primer》第五版中文版习题答案

Results 60 Cpp_Primer_Answers issues
Sort by recently updated
recently updated
newest added

21行`// memmbers` 应为`// members`

第48行应该改为day = stoi(s.substr(s.find_first_of("123456789"), s.find_last_of(" ") - s.find_first_of("123456789")));------------虽然不会报错!

原题目中count为整型,但在程序中把count当成了int*,是题目的本意就是int* count吗

此节在于讲解 constexpr和常量表达式,对应练习最好用到。 对此节,更合适的解法是改为: const int null = 0, * p = null; // p 是 low-level const constexpr int null = 0, * p = null;// p是 top-level const

r1 = v2;//应该非法,非常量引用指向一个常量对象

[练习19.14](https://github.com/huangmingchuan/Cpp_Primer_Answers/blob/master/ch19/README.md#%E7%BB%83%E4%B9%A01914) ```cpp class Screen { public: typedef std::string::size_type pos; char get_cursor() const { return contents[cursor]; } char get() const; char get(pos ht, pos wd) const; private: std::string contents; pos cursor;...

` while (begin++ != end) { if (*begin == i) return true; } ` 在这段循环中,begin迭代器被++,导致在接下来的查找操作中无法对vector的第一个元素进行判断。

在Window_mgr中的私有成员screens未定义,会导致成员函数clear中的s未定义。 `Screen &s = screens[i];//screens未定义` 在Window_mgr::clear定义前定义私有成员screens:`Window_mgr::Window_mgr():screens{ Screen(8, 5, ' ') }{}`

练习3.17和3.20,怎么停止cin输入继续后面的程序呢?直接ctrl+c程序停止,我试了下可以用getline读入,然后判断字符串是否为空,但练习3.20是要读入整型数字,请问要怎么停止cin?

答案写的是Derived_from_Protected 正确答案应该是Derived_from_Private不合法 因为如果派生类继承基类的方式是公有地或者受保护的,则派生类的成员和友元可以使用派生类向基类的类型转换;反之,如果派生类继承基类的方式是私有的,则不能使用。