Skip to content
mattgruenke edited this page Apr 1, 2018 · 4 revisions

Chapter 1

Chapter 2

Chapter 3

Chapter 4

Chapter 5

Chapter 6

Compiling, Linking, and Examining Programs

Getting Information from the Compiler

Listing 6.1

std::string::reserve() is incorrectly used to resize the string. This changes the allocated size, but not the semantic length. std::string::resize() should be used, instead.

Furthermore, std::string::c_str() is used to obtain a writable pointer into the string. While this generally works, in practice: it violates that function's semantics, will typically produce compiler warnings, and might cause some implementations to malfunction. A drop-in replacement would be std::string::data(), but the non-const version was only standardized in C++17. The most common approach is probably just &(str[0]).

Chapter 7

...