web-dev-qa-db-ja.com

IntelliSense:「#using」ではC ++ / CLIを有効にする必要があります

#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を有効にする必要があります..。

この問題を修正する方法!?

15
Abanoub

プロジェクトの設定が間違っています。具体的には、構成プロパティ、一般、共通言語ランタイムのサポート。

CLRノードでプロジェクトテンプレートの1つを選択してプロジェクトを開始することにより、成功の落とし穴に陥ります。

30
Hans Passant

メニューバーからProject-> Propertiesを選択します。 _Project properties_ウィンドウの[構成] Properties-> Generalで、_Common Language Runtime Support_がCommon Language Runtime Support (/clr)に設定されていることを確認します。

17
zangw

プロジェクト設定で有効にします(プロジェクトを右クリック->設定)。最初のタブにオプションが表示されます。

2
jdehaan

MSDNには、パフォーマンスの違いをテストするための優れた例、ParseとtryParseがあります。 ストップウォッチの例

#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
0
Eugene B