读书人

怎么将 string str = quot;who arequot; 使用

发布时间: 2012-03-01 10:25:47 作者: rapoo

如何将 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;
}

读书人网 >C++

热点推荐