-
Notifications
You must be signed in to change notification settings - Fork 252
Book Errata
mattgruenke edited this page Apr 1, 2018
·
4 revisions
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])
.
...