C++ 字符串转大写:toupper() 函数示例
可以使用标准库函数 'toupper()' 将字符串转换为大写字母。
示例代码:
#include <iostream>
#include <cstring>
#include <cctype>
using namespace std;
int main() {
char str[100];
cout << '请输入字符串:';
cin >> str;
int len = strlen(str);
for (int i = 0; i < len; i++) {
str[i] = toupper(str[i]);
}
cout << '转换后的字符串为:' << str << endl;
return 0;
}
输入:
请输入字符串:hello world
输出:
转换后的字符串为:HELLO WORLD
原文地址: http://www.cveoy.top/t/topic/hWGj 著作权归作者所有。请勿转载和采集!