for each loop ?

I just realized that in Visual C++ I have "for each" loop.
Is the for each loop cross-platform ?

Example code in Visual C++ 2010
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
using namespace std;

int main()
{
  int a[10];
  for each(int b in a)
  {
    cout<<b<<'\n';
  }
  cin.get();
  return 0;
}
No, that is not standard C++. It's probably a compiler extension, which means it will only work in Visual Studio.

The closest thing to a for each loop in C++ is the range-based for loop (C++11), but that is not currently supported by VS.
Topic archived. No new replies allowed.