日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

string 大小写转换

發布時間:2023/12/1 52 豆豆
生活随笔 收集整理的這篇文章主要介紹了 string 大小写转换 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

? ? ? ?STL的algorithm庫確實給我們提供了這樣的便利,使用模板函數transform可以輕松解決這個問題,開發人員只需要提供一個函數對象,例如將char轉成大寫的toupper函數或者小寫的函數tolower函數。

?

transform原型:

1 #include <string> 2 #include <algorithm> 3 using namespace std; 4 5 int main() 6 { 7 string strA = "yasaken@126.com"; 8 string strB = "LURY@LENOVO.com"; 9 printf("Before transform:\n"); 10 printf("strA:%s \n", strA.c_str()); 11 printf("strB:%s \n\n", strB.c_str()); 12 13 transform(strA.begin(), strA.end(), strA.begin(), ::toupper); 14 transform(strB.begin(), strB.end(), strB.begin(), ::toupper); 15 printf("After transform to toupper:\n"); 16 printf("strA:%s \n", strA.c_str()); 17 printf("strB:%s \n\n", strB.c_str()); 18 19 transform(strA.begin(), strA.end(), strA.begin(), ::tolower); 20 transform(strB.begin(), strB.end(), strB.begin(), ::tolower); 21 printf("After transform to lower:\n"); 22 printf("strA:%s \n", strA.c_str()); 23 printf("strB:%s \n\n", strB.c_str()); 24 return 0; 25 }

運行結果:

1 strA:yasaken@126.com 2 strB:LURY@LENOVO.com 3 4 After transform to toupper: 5 strA:YASAKEN@126.COM 6 strB:LURY@LENOVO.COM 7 8 After transform to lower: 9 strA:yasaken@126.com 10 strB:lury@lenovo.com ?? 轉載自:http://blog.csdn.net/zhongyhc/article/details/41686893。

轉載于:https://www.cnblogs.com/superxuezhazha/p/6393101.html

總結

以上是生活随笔為你收集整理的string 大小写转换的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。