在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循环语句,区别在于引用类型可以改变原来的值
#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
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。