for(auto &c:s)与for(auto c:s)

在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

  

posted @ 2017-09-05 15:27  LarryXXXXXXXXX  阅读(4616)  评论(2编辑  收藏  举报