Home > Articles > Programming > C/C++

  • Print
  • + Share This
This chapter is from the book

3.11 Advice

  1. Don't reinvent the wheel; use libraries.

  2. Don't believe in magic; understand what your libraries do, how they do it, and at what cost they do it.

  3. When you have a choice, prefer the standard library to other libraries.

  4. Don't think that the standard library is ideal for everything.

  5. Remember to #include the headers for the facilities you use; see §3.3.

  6. Remember that standard library facilities are defined in namespace std; see §3.3.

  7. Use string rather than char*; see §3.5, §3.6.

  8. If in doubt, use a range-checked vector (such as Vec); see §3.7.2.

  9. Prefer vector<T>, list<T>, and map<key,value> to T[]; see §3.7.1, §3.7.3, §3.7.4.

  10. When adding elements to a container, use push_back() or back_inserter(); see §3.7.3, §3.8.

  11. Use push_back() on a vector rather than realloc() on an array; see §3.8.

  12. Catch common exceptions in main(); see §3.7.2.

  • + Share This
  • 🔖 Save To Your Account