|
-
August 20th, 2009, 11:22 PM
#1
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;
}
-
August 21st, 2009, 02:17 AM
#2
Re: C++/CLI for each loop works for native C++ application!
Is there any question in your post ?
-
August 21st, 2009, 02:26 AM
#3
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.
-
August 21st, 2009, 03:37 AM
#4
Re: C++/CLI for each loop works for native C++ application!
You see, these are two opposite things.
C++/CLI only works in a native C++ application
If it's C++/CLI, how can it be native?
-
August 21st, 2009, 03:52 AM
#5
Re: C++/CLI for each loop works for native C++ application!
 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.
-
August 21st, 2009, 04:17 AM
#6
Re: C++/CLI for each loop works for native C++ application!
 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.
-
August 21st, 2009, 06:06 AM
#7
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|