Accessing Character Elements of an STL String : string at « String « C++






Accessing Character Elements of an STL String

  
#include <string>
#include <iostream>

int main(){
   using namespace std;

   string str ("Hello String");

   for(size_t i = 0; i < str.length(); ++ i){
       cout << "Character [" << i << "] is: ";
       cout << str [i] << endl;
   }
   cout << endl;

   return 0;
}
  
    
  








Related examples in the same category

1.Demonstrating member function at
2.Get a C-Style String from a C++ String
3.Display the characters in a string one at a time by using the indexing operator