原文链接:转自我的个人博客
tolower toupper函数
tolower
函数原型: int tolower(int ch);
函数返回: 返回ch所代表的字符的小写字母
所属文件: <ctype.h>
toupper
函数原型: int toupper(int ch);
函数返回: 与ch相应的大写字母
所属文件: <ctype.h>
#include <iostream>
using namespace std;
int main(){
string s="dsfdsaFSDAF";
for(int i=0;i<s.length();i++){
s[i] = toupper(s[i]);//全部转为大小
}
cout<<s<<endl;
for(int i=0;i<s.length();i++){
s[i] = tolower(s[i]);//全部转为小写
}
cout<<s<<endl;
}
strlwr strupr 函数
strlwr
函数原型: char *strlwr(char *a)
函数功能:将字符串a转换为小写形式
函数返回: 返回指向s参数的指针
所属文件:#include <string.h>
strupr
函数原型:char *strupr(char *a)
函数功能:把字符串a中的串转换成大写
函数返回: 返回指向s参数的指针
所属文件:#include <string.h>
#include <iostream>
#include <string.h>
using namespace std;
int main(){
char s[]="jfWxs";
char *p= strupr(s);
cout<<p<<endl;//JFWXS
p = strlwr(s);
cout<<p<<endl;//jfwxs
}
transform和tolower及toupper进行结合
所属文件:#include
transform(first1,last1,first2,result,binary_op);//first1是第一个容器的首迭代器,last1为第一个容器的末迭代器,first2为第二个容器的首迭代器,result为存放结果的容器,binary_op为要进行操作的二元函数对象或sturct、class
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
string str = "JFwxs";
transform(str.begin(),str.end(),str.begin(),::toupper);
cout<<str<<endl;//JFWXS
transform(str.begin(),str.end(),str.begin(),::tolower);
cout<<str<<endl;//jfwxs
}