IntelliSense: “#using” requires C++/CLI to be enab

2019-01-24 02:23发布

问题:

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

Errors: IntelliSense: "#using" requires C++/CLI to be enabled....

how to fix this prob!?

回答1:

Your project settings are wrong. Specifically Configuration Properties, General, Common Language Runtime support.

Fall in the pit of success by starting your project by picking one of the project templates in the CLR node.



回答2:

Choose Project -> Properties from the menu bar. In the Project properties window, under Configuration Properties -> General, make sure that Common Language Runtime Support is set to Common Language Runtime Support (/clr)



回答3:

Enable it in your project settings (right click on the projet -> settings) the first tab should provide the option.



回答4:

The MSDN has a nice example for testing the difference in performance, Parse vs 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


标签: c++-cli