在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刪除。