首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

怎么将 string str = "who are" 使用 toupper()将其转换为大写

2012-03-01 
如何将 string str who are 使用 toupper()将其转换为大写?rt,[解决办法]C/C++ code#include iostre

如何将 string str = "who are"; 使用 toupper()将其转换为大写?
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;
}

热点排行