怎么将 string str = "who are" 使用 toupper()将其转换为大写
如何将 string str = "who are"; 使用 toupper()将其转换为大写?
rt,
------解决方案--------------------
rt,
------解决方案--------------------
- C/C++ code
#include <iostream> #include <string> #include <algorithm> using namespace std; void toUpper(std::string& str) { std::transform(str.begin(), str.end(), str.begin(), ::toupper); } int main() { string str = "who are"; toUpper(str); cout << str << endl; return 0; }
------解决方案--------------------
- C/C++ code
#define UPPER(szSrc, nLen) {for(int i = 0; i < nLen; i++){szSrc[i] = toupper(szSrc[i]);}} int main() { string str = "who are"; UPPER(str, str.length()); cout << str << endl; return 0; }
------解决方案--------------------
[code=C/C++][/code]
#inlucde<stdio.h>
#include<ctype.h>
int main()
{
char *str="who are";
while(*str){
*str=toupper(*str);
str++;
}
printf("%s\n",str);
return 0;
}
}
------解决方案--------------------
哦我晕 应该用一个指针指向str 我错了...
应该这样
#inlucde<stdio.h>
#include<ctype.h>
int main()
{
char *str="who are";
char *p=str;
while(*p){
*p=toupper(*p);
p++;
}
printf("%s\n",str);
return 0;
}