C++のforループの5つの文法を知っていますか?
最新のC++では、forループをサポートする5つの使い方を知っていますか?
見識はありますか.第4の用法ではLambda式に触れた.
ますます簡略化されているのではないでしょうか.
#include
#include
//////////////////////////////////////////////
int nArray[] = {0, 1, 2, 3, 4, 5};
std::vector vecNum(nArray, nArray + 6);
CString strText;
// : ( )
for (size_t i = 0; i < vecNum.size(); ++i)
{
strText.Format("%d", nArray[i]);
AfxMessageBox(strText);
}
// : ( )
for (auto it = vecNum.begin(); it != vecNum.end(); ++it)
{
strText.Format("%d", *it);
AfxMessageBox(strText);
}
// : ( vs2008 )
for each(auto item in vecNum)
{
strText.Format("%d", item);
AfxMessageBox(strText);
}
// :STL
std::for_each(vecNum.begin(), vecNum.end(), [](int item){
CString strText;
strText.Format("%d", item);
AfxMessageBox(strText);
});
// :C++11 (VS2012 )
for(auto item : vecNum)
{
strText.Format("%d", item);
AfxMessageBox(strText);
}
見識はありますか.第4の用法ではLambda式に触れた.
ますます簡略化されているのではないでしょうか.