Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / September 2005

Tip: Looking for answers? Try searching our database.

Does MC++ have foreach?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Edward Yang - 06 Sep 2005 02:28 GMT
I am testing VS 2005 Express August CTP.

I am very thrilled by the fact that I can write code agaist the .NET
Framework (in new syntax). Now I have a question - I want to enumerate
all elements in a collection. In C# or VB, I'd use foreach or For Each.
But classic C/C++ does not have such a keyword. I want to know if there
is a workaround or template function?
Carl Daniel [VC++ MVP] - 06 Sep 2005 03:52 GMT
> I am testing VS 2005 Express August CTP.
>
[quoted text clipped - 3 lines]
> Each. But classic C/C++ does not have such a keyword. I want to know
> if there is a workaround or template function?

C++/CLI (as implemented in VS2005) includes for each (two words) - use it
just like you would in C#

See http://msdn2.microsoft.com/library/ms177202(en-us,vs.80).aspx

-cd
Edward Yang - 06 Sep 2005 05:35 GMT
Thanks. It's amazing!

>>I am testing VS 2005 Express August CTP.
>>
[quoted text clipped - 10 lines]
>
> -cd
Nishant Sivakumar - 08 Sep 2005 20:05 GMT
You can use "for each" in native apps too [it's a non-standard feature you'd
find pretty handy]

Signature

Regards,
Nish [VC++ MVP]

> Thanks. It's amazing!
>
[quoted text clipped - 12 lines]
>>
>> -cd
Nishant Sivakumar - 08 Sep 2005 20:11 GMT
In case that's not clear, here's some code (compiled without /clr) :-

#include <iostream>
#include <vector>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
vector<int> vecint;
vecint.push_back(100);
vecint.push_back(500);
vecint.push_back(200);
for each(int i in vecint)
 cout << i << endl;
}

Signature

Regards,
Nish [VC++ MVP]
http://www.voidnish.com
http://blog.voidnish.com

> You can use "for each" in native apps too [it's a non-standard feature
> you'd find pretty handy]
[quoted text clipped - 15 lines]
>>>
>>> -cd
Edward Yang - 09 Sep 2005 04:43 GMT
Thanks again for your code. I did not realize that it also works for
native code. That's amazing (again). :-)

> In case that's not clear, here's some code (compiled without /clr) :-
>
[quoted text clipped - 11 lines]
>   cout << i << endl;
> }

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.