Hello World using C++ /CX

As is customary with programming languages, here is a Hello World introduction using C++ /CX.

 

   1: #include <iostream>

   2: using namespace std;

   3:  

   4: #using "platform.winmd"

   5:  

   6: using namespace Platform;

   7:  

   8: int __cdecl main()

   9: {

  10:     String^ str = "Hello World";

  11:     wcout << str->Data() << endl;

  12: }

In order to compile this code, make sure you set the winmd directory containing “platform.winmd” using the LIBPATH environment variable.

Compile this code from the command line using cl.exe and link.exe

   1: a.    Cl.exe /c /ZW /ZI /EHsc <filename.cpp>

then link using the following command

   1: a.    Link.exe <filename>.obj vccorlib.lib runtimeobject.lib ole32.lib /SUBSYSTEM:CONSOLE

That’s it. Your first program using C++ /CX is now ready. Execute it at the command line and it should print the message “Hello World” to the console.