使用 C++ 中 STL 將整個字串轉換為大寫或小寫
在本教程中,我們將討論一個使用 C++ 中 STL 將整個字串轉換為大寫或小寫的程式。
為了執行此轉換,C++ STL 提供了 toupper() 和 tolower() 函式,分別轉換為大寫和小寫。
示例
#include<bits/stdc++.h> using namespace std; int main(){ string su = "Tutorials point"; transform(su.begin(), su.end(), su.begin(), ::toupper); cout << su << endl; string sl = "Tutorials Point"; transform(sl.begin(), sl.end(), sl.begin(), ::tolower); cout << sl << endl; return 0; }
輸出
TUTORIALS POINT tutorials point
廣告