Running in Release mode in Visual C++

To speed up your program, you can build your program in the Release configuration instead of the Debug configuration. Programs built in the Release configuration run much faster than in the Debug configuration, but you lose the ability to get much information from the debugger if you're using it to track down a bug. (You can always switch the configuration back from Release to Debug if you like.) Here's what you do in Visual C++:

  1. In the source file that contains the main routine, add these lines at the top of the file, outside of any function or class:

    	#if defined(_WIN32)  &&  !defined(_DEBUG)
    	#include <iostream>
    	#include <windows.h>
    	#include <conio.h>
    
    	struct KeepWindowOpenUntilDismissed
    	{
    	    ~KeepWindowOpenUntilDismissed()
    	    {
    	        DWORD pids[1];
    	        if (GetConsoleProcessList(pids, 1) == 1)
    	        {
    	            std::cout << "Press any key to close this window . . . ";
    	            _getch();
    	        }
    	    }
    	} keepWindowOpenUntilDismissed;
    	#endif
    

    There is no need to remove these lines even if you go back to running in Debug mode or you run under g32 or clang++. You may leave them in a program you turn in.

  2. In the Build menu, select Configuration Manager.

  3. In the drop-down list under Active Solution Configuration, select Release instead of Debug, and then close that dialog.