vector和toupper

hywxn1 2014-04-06 08:39:43
定义了一个vector对象,然后用toupper来变为大写,编译不成功,用的是VS2012,是编译器的问题吗
vector<string> v(1,"a");
for(auto &c:v)
c=toupper(c);
cout<<v<<endl;
...全文
135 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
buyong 2014-04-08
  • 打赏
  • 举报
回复
引用 3 楼 u014514014 的回复:
[quote=引用 2 楼 jianwen0529 的回复:] vs2012不支持C++2011特性 for(auto &c:v) c=toupper(c); //如1L说的 cout<<v<<endl;//不能输出一个vector<string>对象
但是C++primer上面有写: string s("hello world"); for(auto &c:s) c=toupper(c); cout<<s<<endl; 现在s是string变量,toupper能编译通过,如果要是定义成vector<string> s("hello world");编译就不对,为什么呢[/quote] toupper(char) c is a char type
幻夢之葉 2014-04-08
  • 打赏
  • 举报
回复
引用 3 楼 u014514014 的回复:
[quote=引用 2 楼 jianwen0529 的回复:] vs2012不支持C++2011特性 for(auto &c:v) c=toupper(c); //如1L说的 cout<<v<<endl;//不能输出一个vector<string>对象
但是C++primer上面有写: string s("hello world"); for(auto &c:s) c=toupper(c); cout<<s<<endl; 现在s是string变量,toupper能编译通过,如果要是定义成vector<string> s("hello world");编译就不对,为什么呢[/quote] 简单说vector<string> 就是一个数组,里面的元素是string类型,你要取得string就得先取得某个string
ri_aje 2014-04-08
  • 打赏
  • 举报
回复

int main()
{
    vector<string> v(1,"a");
    for(auto& s:v)
        for (auto& c:s)
            c=char(toupper(c));
    for(auto const& s:v)
        cout<<s<<endl;
}
qq120848369 2014-04-07
  • 打赏
  • 举报
回复
你的元素是string噢,不是char。
taodm 2014-04-07
  • 打赏
  • 举报
回复
楼主,你的基础比较弱,不适合继续看C++primer第五版,换第四版吧。 生命可贵,别折腾啊。
hywxn1 2014-04-07
  • 打赏
  • 举报
回复
引用 2 楼 jianwen0529 的回复:
vs2012不支持C++2011特性 for(auto &c:v) c=toupper(c); //如1L说的 cout<<v<<endl;//不能输出一个vector<string>对象
但是C++primer上面有写: string s("hello world"); for(auto &c:s) c=toupper(c); cout<<s<<endl; 现在s是string变量,toupper能编译通过,如果要是定义成vector<string> s("hello world");编译就不对,为什么呢
幻夢之葉 2014-04-07
  • 打赏
  • 举报
回复
vs2012不支持C++2011特性 for(auto &c:v) c=toupper(c); //如1L说的 cout<<v<<endl;//不能输出一个vector<string>对象

64,646

社区成员

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

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