18
#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!?

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Abanoub
  • 3,623
  • 16
  • 66
  • 104

5 Answers5

31

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.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • 13
    Sorry, this is not a subscription service. One question, one answer. Start a new question. – Hans Passant Feb 11 '11 at 13:26
  • Is your advice here specifically to use CLR (as opposed to e.g. Win32)? Or are you suggesting simply to start from any one of the templates? I have seen advice (in a video course) to avoid the CLR stuff because it is managed code, so slower and too Windows-specific. (Of course, the original question looks like it was Windows-specific, so I suspect this is why you suggested CLR. I wonder if this is the only reason.) – RoG Feb 14 '17 at 13:19
  • Use a CLR project template when you *need* to use managed code. If you don't know whether you need to then the most likely answer is "you don't". The OP needed to. – Hans Passant Feb 14 '17 at 13:24
28

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)

In VS2019 it the steps would be :

  • 1/ Right click on the project

  • 2/ Project

  • 3/ Properties

  • 4/ Configuration Properties

  • 5/ Advanced

  • 6/ Common Language Runtime Support change it to Common Language Runtime Support(/clr)

zangw
  • 43,869
  • 19
  • 177
  • 214
3

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

jdehaan
  • 19,700
  • 6
  • 57
  • 97
0

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
Eugene B
  • 9
  • 1
  • 1
    abanoub was asking to fix a problem with the compiler error. Not a performance question... – Hacky Jul 06 '18 at 08:04
0

If you are using Visual Studio, you might have to do some installations pre-hand. To install those, open the Visual Studio Installer from the Windows Start menu. Make sure that the Desktop development with C++ tile is checked, and in the Optional components section, also check C++/CLI Support.

Rory
  • 1
  • 3