新的“自动”问题功能 [英] Problem with the new "auto" functionality

查看:59
本文介绍了新的“自动”问题功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的实际编程工作台是MS Visual Studio C ++ 2010 SP1Rel。



我想编写类似的代码:



My actual programming workbench is MS Visual Studio C++ 2010 SP1Rel.

I want to code something like:

void print_vector(vector <int>& vec)
{
    for (auto &elem : vec)
        cout << elem << " ";
}





但MS说没有。



是真的有必要升级到VS 2012还是有另一种方式?



提前谢谢。



but MS says no.

Is it really necessary to upgrade to VS 2012 or is there another way?

Thanks in advance.

推荐答案

看来2010年并不支持你要做的事情。



会员9586495似乎从我能看到的内容中得到了正确答案。< br $>


请参阅以下内容以了解VS 2010中的用法:

http://msdn.microsoft.com/en-us/library/dd293667%28v=vs.100%29.aspx [<一个href =http://msdn.microsoft.com/en-us/library/dd293667%28v=vs.100%29.aspxtarget =_ blanktitle =New Window> ^ ]
It appears that 2010 doesn''t support what you''re trying to do.

Member 9586495 appears to have the right answer from what I can see.

See the following for usage in VS 2010:
http://msdn.microsoft.com/en-us/library/dd293667%28v=vs.100%29.aspx[^]


作为成员9586495 已经注意到,不是 auto 关键字使用问题。而是基于范围的 [ ^ ]构造(由VS 2012支持,但VS 2010不支持,例如,请参阅:MSVC10 Visual Studio 2010是否支持基于C ++范围的循环 [ ^ ]。
As Member 9586495 already noted, is not the auto keyword usage the problem. It is instead the range-based for[^] construct (supported by VS 2012, but not supported by VS 2010, see, for instance: "Does MSVC10 Visual Studio 2010 support C++ range based loops"[^] at Stack Overflow.


这篇关于新的“自动”问题功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆