编译错误,“对于每个”循环在C ++ VS2010 [英] Compilation error with "for each" loop in C++ VS2010

查看:166
本文介绍了编译错误,“对于每个”循环在C ++ VS2010的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在家里做一个小C ++项目,我带到学校给我的老师。在家里我有Visual Studio 2012,而学校的电脑有Visual Studio 2010.在我的代码,从家里,我有一个for循环,像这样,编译:

I was working on a little C++ project at home, which I brought into school to show my teacher. At home I have Visual Studio 2012, whereas the school computers have Visual Studio 2010. In my code, from home, I had a for loop, like so, which compiled:

for(char c : myStr){...}



However, when I tried it on my school's computers, it did not compile, and I ended up having to do this instead:

for each(char c in myStr){...}

为什么是这种情况? / p>

Why is this the case?

推荐答案

for(char c:myStr){...} 语法是新的 C ++ 11 ,所以使用旧版本 C ++ 的任何东西都不会用该语法编译。

The for(char c : myStr){...} syntax is new with C++11, so anything using an older version of C++ won't compile with that syntax.

在C ++ 11之前, for_each 定义在算法头。

Previous to C++11, for_each is defined in the algorithm header.

这篇关于编译错误,“对于每个”循环在C ++ VS2010的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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