Monday, January 16, 2012

Hello Visual C++ CLR Console Application using Microsoft Visual Studio 11 Developer Preview

- Click New project.. in the start-up page.
New Project...

- Select Visual C++ CLR Console Application, name it CLRConsole, and click OK.
Select template of Visual C++ CLR Console Application

- It's easy to notice on the auto-generated source code, CLRConsole.cpp:
: The parameters passed to main() is (array<System::String ^> ^args). To know more about "^", refer to the post ^ (Handle to Object on Managed Heap).
: The output using Console::, not cout.
: The 'L' in front of "Hello World" indicate that it's wide-character string.

Auto-generated Visual C++ CLR Console Application

- Modify to add following code before return, to make the program pause before exit.
Console::ReadLine();

// CLRConsole.cpp : main project file.

#include "stdafx.h"

using namespace System;

int main(array<System::String ^> ^args)
{
   Console::WriteLine(L"Hello World");
   Console::ReadLine();
   return 0;
}


- Save and Run.
Hello Visual C++ CLR Console Application

No comments:

Post a Comment