Making and Using STL Objects

Read Chapter 2 for an introduction to basic STL classes and their application.

Summary

The intent of this chapter is to show you how easy object-oriented programming can be – if someone else has gone to the work of defining the objects for you. In that case, you include a header file, create the objects, and send messages to them. If the types you are using are powerful and well-designed, then you won’t have to do much work and your resulting program will also be powerful.

In the process of showing the ease of OOP when using library classes, this chapter also introduced some of the most basic and useful types in the Standard C++ library: the family of iostreams (in particular, those that read from and write to the console and files), the string class, and the vector template. You’ve seen how straightforward it is to use these and can now probably imagine many things you can accomplish with them, but there’s actually a lot more that they’re capable of. Even though we’ll only be using a limited subset of the functionality of these tools in the early part of the book, they nonetheless provide a large step up from the primitiveness of learning a low-level language like C. and while learning the low-level aspects of C is educational, it’s also time consuming. In the end, you’ll be much more productive if you’ve got objects to manage the low-level issues. After all, the whole point of OOP is to hide the details so you can "paint with a bigger brush".

However, as high-level as OOP tries to be, there are some fundamental aspects of C that you can’t avoid knowing, and these will be covered in the next chapter.