c++ string 類型 大小寫轉換 


還是用以前的庫函數就行的,toupper(int c)小寫變大寫和tolower(int c)大寫變小寫

可以直接這么干

1 string s = "ABCDEFG";
2 
3     for( int i = 0; i < s.size(); i++ )
4     {
5         s[i] = tolower(s[i]);
6     }
7 
8     cout<<s<<endl;

參考了大佬的博客園,發現stl 中有個叫transform 的函數

今天來一起遞歸預習一下

1     string s = "ABCDEFG";
2     string result;
3 
4     transform(s.begin(),s.end(),s.begin(),::tolower);
5     cout<<s<<endl;
6     return 0;

 

 別忘了包含一下algorithm頭文件


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM