#include <algorithm>#include<vector>//////////////////////////////////////////////intNarray[] = {0,1,2,3,4,5};std::vector<int> Vecnum (nArray, NArray +6); CString StrText;//first usage: The most primitive Syntax (subscript) for(size_t i =0; I < vecnum.size (); ++i) {Strtext.format ("%d", Narray[i]); AfxMessageBox (StrText);}//second usage: The most primitive syntax (with iterators) for(Auto it = Vecnum.begin (); It! = Vecnum.end (); + +it) {Strtext.format ("%d", *it); AfxMessageBox (StrText);}//third usage: simplifying array traversal syntax (supported from VS2008) forEach (Auto iteminchvecnum) {Strtext.format ("%d", item); AfxMessageBox (StrText);}//Fourth usage: STL functionsStd::for_each (Vecnum.begin (), Vecnum.end (), [] (intItem) {CString strText; Strtext.format ("%d", item); AfxMessageBox (StrText); });//Fifth usage: c++11 new additions (VS2012 support) for(Auto Item:vecnum) {Strtext.format ("%d", item); AfxMessageBox (StrText);}
Several ways of C++for