Often when iterating through a string (or any enumerable object), we are not only interested in the current value, but also the position (index). To accomplish this by using
Like this:
std::string s("Test string"); std::string::iterator it = s.begin(); //Use the iterator... ++it; //... std::cout << "index is: " << std::distance(s.begin(), it) << std::endl;