1. 程式人生 > >#C++11新特性 for迴圈遍歷容器#

#C++11新特性 for迴圈遍歷容器#

#include<iostream>
#include<string>
using namespace std;
string s = "hello";
for (auto &i : s )
i = toupper(i); //改變成大寫,影響s的值
cout<<s<<endl;   //s的值是 HELLO

--------------------------------------------------------------

程式碼2:
#include<iostream>
#include<string>
using namespace std;
string s = "hello";
for (auto i : s )
i = toupper(i);   //改變成大寫,不影響s的值
cout<<s<<endl;   //s的值是 hello
--------------------------------------------------------------