When using Visual Studio, I can write a container traversal in at least the following three ways. Which way is preferable? Assuming:
vector<CString> strings1;
Method 1 (using the for_each
algorithm with a lambda:
for_each(strings1.begin(), strings1.end(), [](CString s){
_tprintf(_T("%s"), s);
}
Method 2 (using for each, in
, microsoft specific):
for each(auto s in strings1)
{
_tprintf(_T("%s"), s);
}
Method 3 (treat the vector with array syntax):
for (int i=0; i<v.size(); ++i)
{
_tprintf(_T("%s"), v[i]);
}
I am aware that method 2 is not portable, but I don't care about being portable. This only needs to work in Windows.