Monday, April 02, 2018

Creating your first C++ Console Application in Visual Studio 2017 Community

If you do not find the template for Console Application in Visual Studio 2017 Community's New Project window, read this here.

Launch VS 2017 Community and click New Project and expand the Visual C++ and Click Windows Desktop as shown. Provide a name, herein CplusDektop_1 and click OK. The program is saved to the default location (C:\Users\Owner\source\repos)


DTConsole_0.png

When you click OK, the program files/folder will be created as shown in the solution explorer.


DTConsole_1.png

There are two source files, CplusDesktop_1.cpp and stdafx.cpp. The CplusDekstop_1.cpp has the main() program as shown and is the entry point for the application:


DTConsole_2.png


The stdafx.cpp contains the pre-compiled type application and contains the header file stdafx.h. You may add other header file information if you need to, here.


DTConsole_3.png

You get intellisense support as shown and you should be looking forward to it as it increases productivity.


DTConsole_4.png
With the 'std' namespace added, the CPP file appears as shown.


DTConsole_5.png

Let us program  a 'Hello World" example.

You want to display 'Hello World' when the program is run. For getting input or putting out output you need to include the following:
#include <iostream>

With this added, your cpp file is as shown. 


Click Build solution from the main menu. You should see this:


DTConsole_7.png

Go to Debug menu as shown.



Click Start Without Debugging. The program runs and you see Hello World printed to the console as shown.


No comments:

DMCA.com Protection Status