Skip to content

Instantly share code, notes, and snippets.

@justimchung
Created November 21, 2016 21:40
將字串中的字元全轉成小寫
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
string s = "How are You";
/*transform 是定義在 algorithm 中的,記得要 #include<algorithm>
*transform 會掃描 s 的每個字元,並針對每個字元呼叫 tolower 函式。
*tolower 函式會把每個字元轉成小寫。
*/
transform(s.begin(), s.end(), s.begin(), tolower);
cout << s << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment