string str("some string")
for (auto c : str)
{
// c的类型是char,每次迭代,str的下一个字符被拷贝给c
cout << c << endl; //对于str中的每个字符,输出当前字符
}
// 使用范围for语句改变字符串中的字符
for (auto &c :str)
{
c = 'a';
}
string str("some string")
for (auto c : str)
{
// c的类型是char,每次迭代,str的下一个字符被拷贝给c
cout << c << endl; //对于str中的每个字符,输出当前字符
}
// 使用范围for语句改变字符串中的字符
for (auto &c :str)
{
c = 'a';
}