码迷,mamicode.com
首页 > 编程语言 > 详细

c++ string 类型 大小写转换

时间:2020-02-19 13:14:18      阅读:62      评论:0      收藏:0      [点我收藏+]

标签:text   color   string   今天   int   res   ati   abc   nbsp   

还是用以前的库函数就行的,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头文件

c++ string 类型 大小写转换

标签:text   color   string   今天   int   res   ati   abc   nbsp   

原文地址:https://www.cnblogs.com/zhmlzhml/p/12330497.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!