H. STL Classes and Objects

Although the Standard Template Library (STL) supports many useful templates, this appendix summarizes the use of just three (the ones used in this book):

• The string class

• The list template

• The stack template

The STL String Class

The features in this section require including <string>.

STL string objects are declared simply as string—or std::string if the std namespace is not being used. The simple string class actually instantiates the template class basic_string for type char, so the functions listed here are also supported by basic_string classes:

#include <string>basic_string<char>     s1;    // Equivalent to stringbasic_string<wchar_t>  s2 = L"Hello";  // Wide stringwcout << s2;

Once declared, string objects ...

Get C++ Without Fear: A Beginner’s Guide That Makes You Feel Smart, Second 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.