在c11标准下可以执行的特殊格式的for循环语句,区别在于引用类型可以改变原来的值
#include<iostream>
using namespace std;
int main()
{
string s("hello world");
for(auto c:s)
c='t';
cout<<s<<endl;//结果为hello world
for(auto &c:s)
c='t';
cout<<s<<endl; //结果为ttttttttttt

本文探讨了C11标准下特殊格式的for循环语句,重点介绍了引用类型如何改变原始值,通过两个实例对比展示了普通元素访问和引用访问的区别。
2万+

被折叠的 条评论
为什么被折叠?



