#include <iostream>
#include <string>
using namespace std;
int main() {
// C++标准库函数实现方法
string s = "AbcdEFG";
// 把S字符串转成大写
for (int i = 0; i <= s.length() - 1; i++) {
s[i] = toupper(s[i]);
}
cout << "大写:" + s << endl;
// 把S字符串转成小写
for (int i = 0; i <= s.length() - 1; i++) {
s[i] = tolower(s[i]);
}
cout << "小写:" << s << endl;
// 也可以在Windows中用非标准的库函数
char str[80] = "AbcdEFG", *p;
p = strupr(str);
cout << "大写:" << p << endl;
p = strlwr(str);
cout << "小写:" << p << endl;
system("pause");
return 0;
}
输出效果: