기본 콘텐츠로 건너뛰기

잘 알려지지 않은 VC 명령어 (for each 문)

vs2005 이상에서 지원하는 "for each"문..

난 왜 모르고 있었을까요..--;;
한눈에 훨씬 잘 들어 오는군요.

- 정의
http://msdn.microsoft.com/en-us/library/ms177202(v=vs.80).aspx

- 사용예
http://msdn.microsoft.com/en-US/library/ms177203(v=vs.80).aspx

// for_each_stl.cpp
// compile with: /EHsc
#include <map>
#include <iostream>
using namespace std;

int main() {
   int retval  = 0;
   map<const char*, int> months;
   
   months["january"] = 31;
   months["february"] = 28;
   months["march"] = 31;
   months["april"] = 30;
   months["may"] = 31;
   months["june"] = 30;
   months["july"] = 31;
   months["august"] = 31;
   months["september"] = 30;
   months["october"] = 31;
   months["november"] = 30;
   months["december"] = 31;
   
   map<const char*, int> months_30;
   
   for each( pair<const char*, int> c in months )
      if ( c.second == 30 )
         months_30[c.first] = c.second;

   for each( pair<const char*, int> c in months_30 )
      retval++;
   
   cout << "Months with 30 days = " << retval << endl;
}

또 다른 C++ 명령어 sealed, final
http://rein.kr/blog/archives/558
http://sweeper.egloos.com/2994409
http://blog.naver.com/PostView.nhn?blogId=kzh8055&logNo=140150075988

그 외에 추가된 VS2010 의 기능들
http://jameroid.tistory.com/entry/vs-2010-vc-10


댓글