accessing characters in string objects : string subscript indexer « string « C++ Tutorial






#include <iostream>  
  #include <string>  
  using namespace std;  
    
  int main(){  
     char charray[80];  
     string word;  
    
     cout << "Enter a word: ";  
     cin >> word;  
     int wlen = word.length(); 
    
     cout << "One character at a time: ";  
     for(int j=0; j<wlen; j++)  
        cout << word.at(j);    
    
     word.copy(charray, wlen, 0);
     charray[wlen] = 0;          
     cout << "\nArray contains: " << charray << endl;  
       return 0;  
  }








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