C++/CLI for each loop works for native C++ application!
Hi guys, I just found out the for each syntax used in C++/CLI only works in a native C++ application(no /CLR switch). Below it is some sample code. It cannot work with raw arrays. I have tried it in VS2005 SP1 and VS2010 Beta 1, it works. Too bad, this syntax is incompatible with C++ 0x's for each
Code:
#include <string>
#include <vector>
#include <iostream>
int _tmain(int argc, _TCHAR* argv[])
{
std::vector<int> vec(5);
vec[0] = 1;
vec[1] = 2;
vec[2] = 3;
vec[3] = 4;
vec[4] = 5;
for each (int i in vec)
{
std::wcout<<i;
}
std::wcout<<std::endl;
std::wstring ucs2Text = L"abc";
for each (wchar_t c in ucs2Text)
{
std::wcout<<c;
}
std::wcout<<std::endl;
return 0;
}
Re: C++/CLI for each loop works for native C++ application!
Is there any question in your post ?
Re: C++/CLI for each loop works for native C++ application!
Hi Skizmo, my post is meant to share this interesting discovery with other C++ developers, so there is no question in my post. :)
Re: C++/CLI for each loop works for native C++ application!
You see, these are two opposite things.
Quote:
C++/CLI only works in a native C++ application
If it's C++/CLI, how can it be native? ;)
Re: C++/CLI for each loop works for native C++ application!
Quote:
Originally Posted by CBasicNet
[Hi guys, I just found out the for each syntax used in C++/CLI only works in a native C++ application(no /CLR switch). Below it is some sample code. It cannot work with raw arrays. I have tried it in VS2005 SP1 and VS2010 Beta 1, it works. Too bad, this syntax is incompatible with C++ 0x's for each
More correctly, you mean to say that the for each syntax from C++/CLI is available as a language extension for (recent) Microsoft C++ compilers.
Re: C++/CLI for each loop works for native C++ application!
Quote:
Originally Posted by
cilu
You see, these are two opposite things.
If it's C++/CLI, how can it be native? ;)
There is a typo, remove the "only". Laserlight got it correct on what I actually meant. Just too bad, this for-each is not ISO-C++ compliant code.
Re: C++/CLI for each loop works for native C++ application!
There is no for each in the standard yet. When development of C++/CLI started, C++0x was in a very early stage.