use iterator : string iterator « string « C++ Tutorial





#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
  string str1("Strings handling is easy in C++");
  string::iterator p;
  unsigned int i;

  // use iterator
  p = str1.begin();
  while(p != str1.end()) 
    cout << *p++;
  cout << endl;


  return 0;
}
Strings handling is easy in C++










15.14.string iterator
15.14.1.Using an iterator to output a string
15.14.2.use iterator
15.14.3.string::npos