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; }