Appendix B, in the programmer's guide to C++, describes the C++ string class. Unfortunately, changes to the draft C++ standard have overtaken this description. The following is equivalent to Appendix B, and is compatible with the latest version of the draft standard.

The C++ string class is called string. To use it, the header file <string> must be included. It is part of the standard template library name space so std::string is its full name, or a suitably located using namespace statement can be used instead. Some C++ compilers have a slightly different string class, but most of the functions described below should be available.

The type size_type is used extensively in the following description. This is an implementation dependent unsigned integral type defined as part of the Standard Template Library. The constant string::npos is the largest representable value of type size_type.

Some of the string member functions are overloaded on the type of their input string parameters. These parameters have the following form:




Substring operations

Character access

Utility functions


Search operations

Input and output