C++ 循环for 引用 for(string & : )

阅读 143

2022-09-16

#include <iostream>
using namespace std;

int main()
{
//c++范围for语句,处理字符串中的每个字符
//将字符串中的每个小写字母转换为大写字母
string str("I can fly high!");
for(auto &c : str) //使用引用以更改字符的值
c = toupper(c);
cout<<str<<endl;
return 0;
}

精彩评论(0)

0 0 举报