What are the advantages (if any) of initializing the size of a C++ vector as well as other containers? Is there any reason to not just use the default no-arg constructor?
It is a bad example of Bjarne Stroustrup. Instead of the second definitiona
vector phone_book(1000);
it would be much better to write
vector phone_book;
phone_book.reserve( 1000 );
There is no general "good ways" to determine what a good size to start off would be. It depends on the information you possess about the task. But in any case you can use some initial allocation if you are sure that new elements will be added to the vector.