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
You can use standard STL function distance as mentioned before
index = std::distance(s.begin(), it);
Also, you can access string and some other containers with the c-like interface:
for (i=0;i<string1.length();i++) string1[i];