0

有人可以帮助我找到一个解决以下错误:/CLR选项

"fatal error C1190: managed targeted code requires a '/clr' option"

我的配置是..

  • 的Visual Studio 2008
  • 的Windows 7

这里是代码(我通过使用网络资源得到)

#using <mscorlib.dll> 
using namespace System; 
using namespace System::IO; 

int main() { 
    // Create a reference to the current directory. 
    DirectoryInfo* di = new DirectoryInfo(Environment::CurrentDirectory); 
    // Create an array representing the files in the current directory. 
    FileInfo* fi[] = di->GetFiles(); 
    Console::WriteLine(S"The following files exist in the current directory:"); 
    // Print out the names of the files in the current directory. 
    Collections::IEnumerator* myEnum = fi->GetEnumerator(); 
    while (myEnum->MoveNext()) { 
     FileInfo* fiTemp = __try_cast<FileInfo*>(myEnum->Current); 
     Console::WriteLine(fiTemp->Name); 
    } 
} 
+1

您是否已经为编译器使用了/ clr选项?因为这基本上是错误消息告诉你的:http://msdn.microsoft.com/library/k8d11d4s%28VS.80%29.aspx – 2010-05-20 14:36:17

回答

5

只要做错误消息的建议。它说你必须在使用托管代码时启用/ clr选项,这就是你正在做的事情。将/ clr开关添加到编译器命令行,或者在项目设置中启用CLR(公共语言运行时)支持。

+0

我测试了这个...它的工作原理,所以+1 – gpuguy 2012-11-10 13:55:03

0

我相信mscorlib是自动链接的,而不是你必须手动引用它。