Chapter 7: Strings, Streams, and Formatting
The STL string
class is a powerful, full-featured tool for storing, manipulating, and displaying character-based data. It has much of the convenience you would find in a high-level scripting language, yet remains as quick and agile as you would expect from C++.
The string
class is based on basic_string
, a contiguous container class that may be instantiated with any character type. Its class signature looks like this:
template< typename CharT, typename Traits = std::char_traits<CharT>, typename Allocator = std::allocator<CharT> > class basic_string;
The Traits
and Allocator
template parameters are usually left to their default values.
The underlying storage of basic_string
is a contiguous sequence of CharT
, and can be accessed with the data()
member function:
const std::basic_string<char> s{"hello...