Today, we found that for each syntax can be directly compiled through, and previously thought that only open the/clr to support. Check the information found that Ms from VS2005 has been supported. Although not conform to the standard but it is really convenient ah, it must be recorded.
See here, has already been introduced. Http://www.codeproject.com/Tips/76166/For-each-loop-in-Native-C
Since Visual Studio2005, native C + + has had a ' forEach ' loop construct, like C # or Java. Unfortunately it isRestricted to Collections fromThe STL library, such asvector. However, it does mean you can write very neat code to iterate through such a collection:vector<int> Data (3);d ata[0] =Ten;d ata[1] = -;d ata[2] = -;//instead of thisintTotal =0; for(vector<int>::iterator VI = Data.begin (); VI! = Data.end (); vi++){ inti = *VI; Total+=i;} cout<<"Total:"<< Total <<Endl;//Do this :Total =0; foreachConst intIinchdata) Total+=I;cout<<"Total:"<< Total <<Endl; Now we just need so making part of the C+ + standard! If you is writing standard compliant code, you'll have the For_each function [^].
For Each loop in Native C + +