【问题标题】:IntelliSense: "#using" requires C++/CLI to be enabledIntelliSense:“#using”需要启用 C++/CLI
【发布时间】:2021-12-17 20:37:09
【问题描述】:
#using <mscorlib.dll>
#using <System.dll>
using namespace System;
using namespace System::Text;
using namespace System::IO;
using namespace System::Net;
using namespace System::Net::Sockets;
using namespace System::Collections;

错误:IntelliSense:“#using”需要启用 C++/CLI....

如何解决这个问题!?

【问题讨论】:

    标签: c++-cli


    【解决方案1】:

    您的项目设置有误。特别是配置属性、常规、公共语言运行时支持。

    通过在 CLR 节点中选择一个项目模板来启动您的项目,从而进入成功的陷阱。

    【讨论】:

    • 对不起,这不是订阅服务。一问一答。开始一个新问题。
    • 您的建议是专门针对使用 CLR(而不是例如 Win32)吗?还是您只是建议从任何一个模板开始?我已经看到建议(在视频课程中)避免使用 CLR 的东西,因为它是托管代码,速度太慢而且太特定于 Windows。 (当然,最初的问题看起来像是特定于 Windows 的,所以我怀疑这就是你建议 CLR 的原因。我想知道这是否是唯一的原因。)
    • 在您需要使用托管代码时使用 CLR 项目模板。如果您不知道是否需要,那么最有可能的答案是“您不需要”。 OP 需要。
    【解决方案2】:

    从菜单栏中选择Project -> Properties。在Project properties 窗口中,在配置Properties -> General 下,确保将Common Language Runtime Support 设置为Common Language Runtime Support (/clr)

    在 VS2019 中,步骤如下:

    • 1/右键项目

    • 2/Project

    • 3/Properties

    • 4/Configuration Properties

    • 5/Advanced

    • 6/Common Language Runtime Support改成Common Language Runtime Support(/clr)

    【讨论】:

    • 酷,这很有帮助。
    【解决方案3】:

    在您的项目设置中启用它(右键单击项目 -> 设置)第一个选项卡应提供该选项。

    【讨论】:

      【解决方案4】:

      MSDN 有一个很好的示例来测试性能差异,Parse 与 tryParse: Stopwatch Example

      #include <stdio.h>
      #using <System.dll>
      
      using namespace System;
      using namespace System::Diagnostics;
      
      void DisplayTimerProperties()
      {
          // Display the timer frequency and resolution.
          if (Stopwatch::IsHighResolution)
          {
              Console::WriteLine("Operations timed using the system's high-resolution performance counter.");
          }
          else
          {
              Console::WriteLine("Operations timed using the DateTime class.");
          }
      
          Int64 frequency = Stopwatch::Frequency;
          Console::WriteLine("  Timer frequency in ticks per second = {0}", frequency);
          Int64 nanosecPerTick = (1000L * 1000L * 1000L) / frequency;
          Console::WriteLine("  Timer is accurate within {0} nanoseconds", nanosecPerTick);
      }
      
      void TimeOperations()
      {
          Int64 nanosecPerTick = (1000L * 1000L * 1000L) / Stopwatch::Frequency;
          const long numIterations = 10000;
      
          // Define the operation title names.
          array<String^>^operationNames = { "Operation: Int32.Parse(\"0\")","Operation: Int32.TryParse(\"0\")","Operation: Int32.Parse(\"a\")","Operation: Int32.TryParse(\"a\")" };
      
          // Time four different implementations for parsing 
          // an integer from a string. 
          for (int operation = 0; operation <= 3; operation++)
          {
              // Define variables for operation statistics.
              Int64 numTicks = 0;
              Int64 numRollovers = 0;
              Int64 maxTicks = 0;
              Int64 minTicks = Int64::MaxValue;
              int indexFastest = -1;
              int indexSlowest = -1;
              Int64 milliSec = 0;
              Stopwatch ^ time10kOperations = Stopwatch::StartNew();
      
              // Run the current operation 10001 times.
              // The first execution time will be tossed
              // out, since it can skew the average time.
              for (int i = 0; i <= numIterations; i++)
              {
                  Int64 ticksThisTime = 0;
                  int inputNum;
                  Stopwatch ^ timePerParse;
                  switch (operation)
                  {
                  case 0:
      
                      // Parse a valid integer using
                      // a try-catch statement.
                      // Start a new stopwatch timer.
                      timePerParse = Stopwatch::StartNew();
                      try
                      {
                          inputNum = Int32::Parse("0");
                      }
                      catch (FormatException^)
                      {
                          inputNum = 0;
                      }
      
                      // Stop the timer, and save the
                      // elapsed ticks for the operation.
                      timePerParse->Stop();
                      ticksThisTime = timePerParse->ElapsedTicks;
                      break;
      
                  case 1:
      
                      // Parse a valid integer using
                      // the TryParse statement.
                      // Start a new stopwatch timer.
                      timePerParse = Stopwatch::StartNew();
                      if (!Int32::TryParse("0", inputNum))
                      {
                          inputNum = 0;
                      }
      
                      // Stop the timer, and save the
                      // elapsed ticks for the operation.
                      timePerParse->Stop();
                      ticksThisTime = timePerParse->ElapsedTicks;
                      break;
      
                  case 2:
      
                      // Parse an invalid value using
                      // a try-catch statement.
                      // Start a new stopwatch timer.
                      timePerParse = Stopwatch::StartNew();
                      try
                      {
                          inputNum = Int32::Parse("a");
                      }
                      catch (FormatException^)
                      {
                          inputNum = 0;
                      }
      
                      // Stop the timer, and save the
                      // elapsed ticks for the operation.
                      timePerParse->Stop();
                      ticksThisTime = timePerParse->ElapsedTicks;
                      break;
      
                  case 3:
      
                      // Parse an invalid value using
                      // the TryParse statement.
                      // Start a new stopwatch timer.
                      timePerParse = Stopwatch::StartNew();
                      if (!Int32::TryParse("a", inputNum))
                      {
                          inputNum = 0;
                      }
      
                      // Stop the timer, and save the
                      // elapsed ticks for the operation.
                      timePerParse->Stop();
                      ticksThisTime = timePerParse->ElapsedTicks;
                      break;
      
                  default:
                      break;
                  }
      
                  // Skip over the time for the first operation,
                  // just in case it caused a one-time
                  // performance hit.
                  if (i == 0)
                  {
                      time10kOperations->Reset();
                      time10kOperations->Start();
                  }
                  else
                  {
                      // Update operation statistics
                      // for iterations 1-10001.
                      if (maxTicks < ticksThisTime)
                      {
                          indexSlowest = i;
                          maxTicks = ticksThisTime;
                      }
                      if (minTicks > ticksThisTime)
                      {
                          indexFastest = i;
                          minTicks = ticksThisTime;
                      }
                      numTicks += ticksThisTime;
                      if (numTicks < ticksThisTime)
                      {
                          // Keep track of rollovers.
                          numRollovers++;
                      }
                  }
              }
      
              // Display the statistics for 10000 iterations.
              time10kOperations->Stop();
              milliSec = time10kOperations->ElapsedMilliseconds;
              Console::WriteLine();
              Console::WriteLine("{0} Summary:", operationNames[operation]);
              Console::WriteLine("  Slowest time:  #{0}/{1} = {2} ticks", indexSlowest, numIterations, maxTicks);
              Console::WriteLine("  Fastest time:  #{0}/{1} = {2} ticks", indexFastest, numIterations, minTicks);
              Console::WriteLine("  Average time:  {0} ticks = {1} nanoseconds", numTicks / numIterations, (numTicks * nanosecPerTick) / numIterations);
              Console::WriteLine("  Total time looping through {0} operations: {1} milliseconds", numIterations, milliSec);
      
          }
      }
      
      int main()
      {
          DisplayTimerProperties();
          Console::WriteLine();
          Console::WriteLine("Press the Enter key to begin:");
          Console::ReadLine();
          Console::WriteLine();
          TimeOperations();
      
          getchar();
      }
      
      
      
      //Operations timed using the system's high-resolution performance counter.
      //Timer frequency in ticks per second = 3319338
      //Timer is accurate within 301 nanoseconds
      //
      //Press the Enter key to begin :
      //
      //
      //
      //Operation : Int32.Parse("0") Summary :
      //  Slowest time : #4483 / 10000 = 95 ticks
      //  Fastest time : #3 / 10000 = 0 ticks
      //  Average time : 0 ticks = 99 nanoseconds
      //  Total time looping through 10000 operations : 1 milliseconds
      //
      //  Operation : Int32.TryParse("0") Summary :
      //  Slowest time : #7720 / 10000 = 187 ticks
      //  Fastest time : #1 / 10000 = 0 ticks
      //  Average time : 0 ticks = 109 nanoseconds
      //  Total time looping through 10000 operations : 1 milliseconds
      //
      //  Operation : Int32.Parse("a") Summary :
      //  Slowest time : #3701 / 10000 = 2388 ticks
      //  Fastest time : #2698 / 10000 = 102 ticks
      //  Average time : 116 ticks = 35109 nanoseconds
      //  Total time looping through 10000 operations : 352 milliseconds
      //
      //  Operation : Int32.TryParse("a") Summary :
      //  Slowest time : #8593 / 10000 = 23 ticks
      //  Fastest time : #1 / 10000 = 0 ticks
      //  Average time : 0 ticks = 88 nanoseconds
      //  Total time looping through 10000 operations : 1 milliseconds
      

      【讨论】:

      • abanoub 要求修复编译器错误问题。不是性能问题...
      【解决方案5】:

      如果您使用的是 Visual Studio,您可能需要预先进行一些安装。要安装它们,请从 Windows 开始菜单中打开 Visual Studio 安装程序。确保选中 Desktop development with C++ 磁贴,并在 Optional components 部分中选中 C++/CLI Support

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-06-04
        • 1970-01-01
        • 2011-07-01
        • 1970-01-01
        • 2014-08-26
        • 1970-01-01
        • 2015-07-24
        相关资源
        最近更新 更多