为什么大小写木有变

flyingzc 2011-07-26 08:27:34
#include<iostream>
#include<vector>
#include<string>
using namespace std;
void myToUpper(std::string& str)
{
for (size_t i=0; i<str.size(); i++)
{
toupper(str[i]);
}
}

int main()
{
string i;
vector<string> vect;
vector<string>::size_type num=0;
cin>>i;
vect.push_back(i);

for(num =0;num!=vect.size();num++)
{
myToUpper(vect[num]);
cout<<vect[num];
}
return 0;
}
...全文
74 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
至善者善之敌 2011-07-26
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 zhang20072844 的回复:]
将第九行改为:
str[i] = toupper(str[i]);
因为toupper这个函数返回的是大写字母,如果按照你写的,肯定不会变,因为你没有接收返回值。
我已经试过了,改完后没有问题。
[/Quote]

++1
AndyZhang 2011-07-26
  • 打赏
  • 举报
回复
将第九行改为:
str[i] = toupper(str[i]);
因为toupper这个函数返回的是大写字母,如果按照你写的,肯定不会变,因为你没有接收返回值。
我已经试过了,改完后没有问题。
c_losed 2011-07-26
  • 打赏
  • 举报
回复

#include<iostream>
#include<vector>
#include<string>
#include <locale>
using namespace std;
void myToUpper(std::string& str, char re)
{
for (size_t i=0; i<str.size(); i++)
{
re = toupper(str[i]);
cout<< re << endl;
}
}

int main()
{
string i;
char n = NULL;
vector<string> vect;
vector<string>::size_type num=0;
cin>>i;

vect.push_back(i);



for(num =0;num!=vect.size();num++)
{
myToUpper(vect[num],n);
//cout<<vect[num];
}



return 0;
}
懒得打字 2011-07-26
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 dizuo 的回复:]

C/C++ code
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;

void myToUpper(std::string& str)
{
for (size_t i=0; i<str.size(); i++)
{
……
[/Quote]
+1
ryfdizuo 2011-07-26
  • 打赏
  • 举报
回复
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;

void myToUpper(std::string& str)
{
for (size_t i=0; i<str.size(); i++)
{
str[i] = toupper(str[i]); // 这里的问题
}
}

int main()
{
string i;
vector<string> vect;
vector<string>::size_type num=0;
while(cin>>i)
{
vect.push_back(i);
}

for_each( vect.begin(), vect.end(), myToUpper );

copy( vect.begin(), vect.end(), ostream_iterator<string>(cout, "\n"));

system("PAUSE");
return 0;
}
/*
one
two
^Z
ONE
TWO
请按任意键继续. . .*/

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧