Access the contents of a string using iterators : string iterator « String « C++






Access the contents of a string using iterators

  
#include <string>
#include <iostream>

int main(){
   using namespace std;

   string str ("Hello String");

   int i = 0;
   string::const_iterator itt;
   for ( itt = str.begin (); itt != str.end (); ++ itt )
   {
       cout << "Character [" << i ++ << "] is: ";
       cout << *itt << endl;
   }

   //The char* representation of the string is: "
   cout << str.c_str () << endl;

   return 0;
}
  
    
  








Related examples in the same category

1.Using an iterator to output a string
2.use iterator
3.string::npos
4.Create an iterator to a string and Use it to cycle through the characters of a string
5.increment the iterator