Modify char in a string by indexer : string subscript indexer « string « C++ Tutorial






#include <iostream>
using std::cout;
using std::endl;

#include <string>
using std::string;

int main()
{
   string string1( "cat" );
   string string2;
   string string3;

   string2 = string1;
   string3.assign( string1 );
   
   cout << "string1: " << string1 << "\nstring2: " << string2
      << "\nstring3: " << string3 << "\n\n";

   string2[ 0 ] = string3[ 2 ] = 'r';

   cout << "string1: " << string1 << "\nstring2: " << string2 << "\nstring3: ";


   return 0;
}
string1: cat
string2: cat
string3: cat

string1: cat
string2: rat
string3: "








15.5.string subscript indexer
15.5.1.Modify char in a string by indexer
15.5.2.Accessing characters in a string
15.5.3.switch statement based on char value
15.5.4.accessing characters in string objects
15.5.5.Is it a string::npos