一、
void f7(){
string s1="AAAbbb";
transform(s1.begin(),s1.end(),s1.begin(),toupper);
cout<<"全部转化为大写:"<<s1<<endl;
transform(s1.begin(),s1.end(),s1.begin(),tolower);
cout<<"全部转化为小写:"<<s1<<endl;
}
结果:全部转化为大写:AAABBB;
全部转化为小写:aaabbb;
二、
#include <iostream>
#include <algorithm>
using namespace std;
char op(char ch)
{
if(ch>='A'&&ch<='Z')
return ch+32;
else
return ch;
}
int main()
{
string first,second;
cin>>first;
second.resize(first.size());
transform(first.begin(),first.end(),second.begin(),op);
cout<<second<<endl;
return 0;
}
https://blog.youkuaiyun.com/sun223173/article/details/80631252
https://blog.youkuaiyun.com/fyf18845165207/article/details/82729859
本文介绍了C++中使用transform函数进行字符串大小写转换的方法,包括将字符串全部转化为大写和小写的实例。
2523

被折叠的 条评论
为什么被折叠?



