在c11標準下可以執行的特殊格式的for循環語句,區別在于引用類型可以改變原來的值
#include<iostream>
using namespace std;
int main()
{string s("hello world");for(auto c:s)c='t';cout<<s<<endl;//結果為hello worldfor(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 worldfor(auto &c:s)c='t';cout<<s<<endl; //結果為ttttttttttt
轉載于:https://www.cnblogs.com/zlspace/p/7478841.html
本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。 如若轉載,請注明出處:http://www.pswp.cn/news/282481.shtml 繁體地址,請注明出處:http://hk.pswp.cn/news/282481.shtml 英文地址,請注明出處:http://en.pswp.cn/news/282481.shtml
如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!