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
For strings, you can use string.c_str() which will return you a const char*, which can be treated as an array, example:
string.c_str()
const char* strdata = str.c_str(); for (int i = 0; i < str.length(); ++i) cout << i << strdata[i];