Programming Guides
General Advice
- 尽量编写具有可读性、可维护性、效率和鲁棒性的代码。
- 计算得到的结果应先用变量保存,再根据需要格式化和输出。
- Microsoft Visual C++ 对
strcpy 等函数给出安全警告时,应先理解更安全的替代方案;旧练习可能需要定义 _CRT_SECURE_NO_WARNINGS。 - 浮点数比较应使用合适的容差,不直接判断精确相等。
- 需要控制小数输出格式时,使用
<iomanip> 中的 std::fixed 和 std::setprecision 等工具。
Focused Examples
Simple class
Strings
Text-file input and output
std::vector
std::list
const
Copy constructors
Dynamic memory and copy constructors
Polymorphism
static
Templates
Friend functions and classes
STL example
Composite patternProgramming Style
C++ 最佳实践
命名规则