10.2. Using the Overloaded Operators of Standard Library Class string

Figure 10.1 demonstrates many of class string’s overloaded operators and several other useful member functions, including empty, substr and at. Function empty determines whether a string is empty, function substr returns a string that represents a portion of an existing string and function at returns the character at a specific index in a string (after checking that the index is in range). Chapter 19 presents class string in detail.

 1   // Fig. 10.1: fig10_01.cpp 2   // Standard Library string class test program. 3   #include <iostream> 4   #include <string> 5   using namespace std; 6  7   int main() 8   { 9      string s1( "happy" );    10 ...

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.