大小写字母转换c++
时间: 2023-12-22 11:28:08 浏览: 33
以下是三种C++中大小写字母转换的方法:
1. 大写转小写
```cpp
#include <iostream>
#include <string.h>
using namespace std;
int main(){
char a[]="AaQqDd";
cout<<strlwr(a)<<endl; // 输出:aaqqdd
}
```
2. 大小写互相转换
```cpp
#include <iostream>
using namespace std;
int main(){
char a = 'A';
a = a ^ 32; // 大写转小写
cout << a << endl; // 输出:a
a = a ^ 32; // 小写转大写
cout << a << endl; // 输出:A
}
```
3. 大小写转换
```cpp
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
string str="awQEasW";
transform(str.begin(),str.end(),str.begin(),::tolower); // 转换为小写
cout<<str<<endl; // 输出:awqeasw
transform(str.begin(),str.end(),str.begin(),::toupper); // 转换为大写
cout<<str<<endl; // 输出:AWQEASW
}
```