In C, if you want to do something like that, you would use strlen(), but generally not in the loop - but instead, once before the loop, storing the value in a local variable. What about the above though - is that the equivalent of calling strlen() a bunch of times, and would it be better to call str.size() once and store it in a variable? Or does C++ do things differently?Code:string str("Hello, world");
for(string::size_type idx = 0; idx != str.size(); ++idx) {
cout << str[idx] << endl;
}
~/