CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Sep 2002
    Location
    Singapore
    Posts
    673

    Post 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;
    }

  2. #2
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: C++/CLI for each loop works for native C++ application!

    Is there any question in your post ?

  3. #3
    Join Date
    Sep 2002
    Location
    Singapore
    Posts
    673

    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.

  4. #4
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    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?
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  5. #5
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    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.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  6. #6
    Join Date
    Sep 2002
    Location
    Singapore
    Posts
    673

    Re: C++/CLI for each loop works for native C++ application!

    Quote Originally Posted by cilu View Post
    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.

  7. #7
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    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.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured