3.3.1. Defining and Initializing vector
s
As with any class type, the vector
template controls how we define and initialize vector
s. Table 3.4 (p. 99) lists the most common ways to define vector
s.
We can default initialize a vector
(§ 2.2.1, p. 44), which creates an empty vector
of the specified type:
vector<string> svec; // default initialization; svec has no elements
It might seem that an empty vector
would be of little use. However, as we’ll see shortly, we can (efficiently) add elements to a vector
at ...
Get C++ Primer, Fifth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.