Hi guys, I just found out the for each syntax used in C++/CLI only works in a native C++ application(no /CLR switch). Below it is some sample code. It cannot work with raw arrays. I have tried it in VS2005 SP1 and VS2010 Beta 1, it works. Too bad, this syntax is incompatible with C++ 0x's for each
Code:#include <string> #include <vector> #include <iostream> int _tmain(int argc, _TCHAR* argv[]) { std::vector<int> vec(5); vec[0] = 1; vec[1] = 2; vec[2] = 3; vec[3] = 4; vec[4] = 5; for each (int i in vec) { std::wcout<<i; } std::wcout<<std::endl; std::wstring ucs2Text = L"abc"; for each (wchar_t c in ucs2Text) { std::wcout<<c; } std::wcout<<std::endl; return 0; }




Reply With Quote