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

#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;
}
posted @ 2022-07-25 15:50  萧海~  阅读(122)  评论(0编辑  收藏  举报