19.8. Replacing Characters in a string

Figure 19.7 demonstrates string member functions for replacing and erasing characters. Lines 10–14 declare and initialize string string1. Line 20 uses string member function erase to erase everything from (and including) the character in position 62 to the end of string1. [Note: Each newline character occupies one character in the string.]

 1   // Fig. 19.7: Fig19_07.cpp 2   // Demonstrating string member functions erase and replace. 3   #include <iostream> 4   #include <string> 5   using namespace std; 6  7   int main() 8   { 9      // compiler concatenates all parts into one string10      string string1( "The values in any left subtree" 11         "\nare less than the value ...

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.