Jerry's Tutorials: Visual Studio Default Program

Jerry's Tutorials: Visual Studio Default Program


I use Microsoft's Visual Studio as my C++ development environment.  Visual Studio provides both the compiler and a complete IDE (Integrated Development Environment).  Before that, I used Borland's C++ compiler and IDE.  Before that, I used things like the vi editor, the cc or gcc compilers, and makefiles.  I much prefer the IDE environments, but using the IDE environments can color your use of C++ just a bit.

In particular, Visual Studio will create for you the following stub of a C++ program to get you started.


#include "stdafx.h"

int _tmain(int argc, _TCHAR* argv[])
{	
	return 0;
}

The #include "stdafx.h" statement is Visual Studio's default way of specifying pre-compiled headers.  Rather than placing your #include statements at the beginning of each .cpp file, you place your #include statements in the stdafx.h file that Visual Studio creates for you, and then you place #include "stdafx.h" at the beginning of each .cpp file.  This procedure will cause all your header files to be pre-compiled.  Programs will not compile in Visual Studio unless you use the #include "stdafx.h" statement, or unless you make some major changes to the stdafx.h file which is provided by the compiler.  Therefore, all my examples will have the #include "stdafx.h" so my programs will compile correctly.  However, I will place all my #include statements in the main program for clarity of the examples.  Such headers will not be pre-compiled and the compile will be a little slower, and the sacrifice of compile speed will be in a good cause.  But do be aware that if you copy and paste my example programs into an environment other that Visual Studio, you may have to delete the #include "stdafx.h" statement.


#include "stdafx.h"

int main()
{	
	return 0;
}

_tmain is a #define value created for you by Visual Studio that reduces down either to wmain or to main depending on whether or not UNICODE is enabled for the program.  For my own use, I always just accept the compiler's default, but for all my examples I will replace _tmain with main to make the things a little simpler.

argc and argv are the most typical variable names used to process command line arguments, going all the way back to Kernighan and Richie's original book about C programming.  _TCHAR is a #define value that reduces down either to wchar or char depending on whether or not UNICODE is enabled for the program.  For my own use, I always just accept the compiler's default, but for all my examples I will leave these items out to make things a little simpler.  Hence, my basic stub of a C++ program will be as appears to the left.


Return to Jerry's Home Page

This page last edited on 23 Mar 2016.