Situ
#include <algorithm>
#include <vector>
int narray[] = {0, 1, 2, 3, 4, 5};
Std::vector<int> Vecnum (NArray, NArray + 6);
CString StrText;
The first usage: the original 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)
For each (auto item in Vecnum)
{
Strtext.format ("%d", item);
AfxMessageBox (StrText);
}
Fourth usage: STL function
Std::for_each (Vecnum.begin (), Vecnum.end (), [] (int item) {
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);
}