Introduction to command line programming in C++ using Visual Studio 2012

The main issue I have with Visual Studio is the lack of intuition it possesses when creating simple command line programs.

First to create a new console application:

File > New > Project >Visual C++ > Win32 > Console Application

YOUR CODE HERE!

Here is where things get annoying:

return 0;

Your program will eventually return so you have a few options to keep the console window open long enough to view the output.

My personal choice:

Use Ctrl+F5 with the Console (/SUBSYSTEM:CONSOLE) linker option enabled.

This option is available as follows:

Solution Explorer > Right click Project > Properties > Configuration Properties > Linker > System > Subsystem

You will see “Press any key to continue . . .” before the window terminates.

Alternate method:

insert cin.get() before the return statement on all console applications.

 cin.get(); return 0;

This method will wait for user input, albeit, with less verbosity.

If you'd like to share this, click below:

Leave a Reply

Your email address will not be published. Required fields are marked *