C++ examples for STL:string
Use an iterator to cycle through the characters of a string.
#include <iostream> #include <string> #include <cctype> #include <algorithm> #include <vector> using namespace std; int main()//from ww w . jav a 2s . co m { string strA("This is a test. another test test test"); // Create an iterator to a string. string::iterator itr; // Use an iterator to cycle through the characters of a string. cout << "Display a string via an iterator.\n"; for(itr = strA.begin(); itr != strA.end(); ++itr) cout << *itr; cout << "\n\n"; return 0; }