开发者

/clr option in c++

开发者 https://www.devze.com 2022-12-31 16:22 出处:网络
Can someone help me find a solution to the following error: \"fatal error C1190: managed targeted code requires a \'/clr\' option\"

Can someone help me find a solution to the following error:

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

My configuration is ..

  • Visual studio 2008
  • Windows 7

Here is the code (i got by using net resources)

#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);
    }
}


Just do what the error message suggests. It says that you have to enable the /clr option when using managed code, which is what you're doing. Either add the /clr switch to the compiler command line, or enable CLR (Common Language Runtime) support in the project settings.


I believe that mscorlib is automatically linked in, instead of you having to manually refer it.

0

精彩评论

暂无评论...
验证码 换一张
取 消