Use the STL

The Standard Template Library (Chapter 16 and Appendix G, “The STL Methods and Functions”) provides ready-made solutions to many programming needs, so use it. For example, instead of declaring an array of double or of string objects, you can create a vector<double> object or a vector<string> object. The advantages are similar to those of using string objects instead of C-style strings. Assignment is defined, so you can use the assignment operator to assign one vector object to another. You can pass a vector object by reference, and a function receiving such an object can use the size() method to determine the number of elements in the vector object. Built-in memory management allows for automatic resizing when you use the pushback() ...

Get C++ Primer Plus, Fourth 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.