19.9. Inserting Characters into a string

Class string provides member functions for inserting characters into a string. Figure 19.8 demonstrates the string insert capabilities.

 1   // Fig. 19.8: Fig19_08.cpp 2   // Demonstrating class string insert member functions. 3   #include <iostream> 4   #include <string> 5   using namespace std; 6  7   int main() 8   { 9      string string1( "beginning end" );10      string string2( "middle " );11      string string3( "12345678" );12      string string4( "xx" );13 14      cout << "Initial strings:\nstring1: " << string115         << "\nstring2: " << string2 << "\nstring3: " << string316         << "\nstring4: " << string4 << "\n\n";17 18      // insert "middle" at location ...

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.