/string_tolower Secret
Created
November 21, 2016 21:40
將字串中的字元全轉成小寫
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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