For Each loop in Native C + +

Source: Internet
Author: User

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 + +

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.