Syntax:
#include <string> iterator begin(); const_iterator begin() const;
The function begin() returns an iterator to the first element of the string. begin() should run in constant time. For example, the following code uses begin() to initialize an iterator that is used to traverse a list:
// Create a list of characters string s = "ABCDEFGHIJ"; // Display the list string::iterator iter; for ( iter = s.begin(); iter != s.end(); ++iter ) { cout << *iter; }