# C++ Notes: IDEs - Dev-C++

Dev-C++ is a reasonably good, simple, free C++ development environment for C++. It provides a GUI interface to gcc (GNU Compiler Collection). I use it rather than the Microsoft's Visual Studio or Borland's C++ Builder because of its simplicity. For small programs it's a good choice. For larger and more complex programs, the commercial products offer more.

## Where to get it

www.bloodshed.net has links for downloading. By default it installs itself in `C:\Dev-Cpp`. You should uninstall the previous version before installing the new version.

## Options

If they aren't already set, you consider setting these options [applies to Dev-C++ 4.9.8.0 - 4.9.1.0].

Tools > Editor options
  A number of editor options that are worth setting if they aren't already turned on. Some are set on by default (Auto Indent, Insert Mode, Find Text at Cursor, Scrollbars as needed, Use Syntax highlighting). Be sure that your tab size is set to 4 (or less). Turn on the `Highlight matching braces/parentheses` option. When this is turned on, selecting a brace will show the matching brace, saving a lot of time when trying understand exactly what's wrong with your braces. In the editor options `Display` tab, select the `Line Numbers` option so that numbers will show on your source code.
Tools > Compiler Options > Settings [tab] > Code Generation [list item]
  Set Enable exception handling to Yes. If you use asserts, it may be necessary to set this option even to get your program to compile.
Tools > Compiler Options > Directories [tab] > C++ Includes [tab]
  Some installations don't have all the C++ Libraries included. For version 4.9.1.1 I show the following, altho I'm not really sure what the implications of all of them are.

         C:\Dev-Cpp\include\c++
         C:\Dev-Cpp\include\c++\mingw32
         C:\Dev-Cpp\include\c++\backward
         C:\Dev-Cpp\include\
         C:\Dev-Cpp\include\c++\3.3.1

  If one is missing, the button to the right of the textfield can be used to browse for new directories.

## Projects are useful for managing multiple source files

A project (contained in a .dev file) is how Dev-C++ (and other IDEs) keep track of multiple source files. If you have only one source file, there is no need to create a project.

- Create a new project with `File > New... > Project` menu item and select `Console` as the type of project from the `Basic` tab and C++ as the type of source code. Don't use a project name that conflicts with a source file name.
- The panel on the left shows the project files.
- Use the `File > New... > Source File` menu item to create new source files in the project (.cpp, .h, etc).
- To delete a source file from the project, right click it in the project panel and select Delete.

## Console window closes when program terminates

This isn't really a bug; it's probably what should happen normally, but it would be nice to have an option to keep it open as some IDEs do. Here are some ways of handing this.

1. `system("PAUSE")`. Put the following statement before the `return 0` in main.

          system("PAUSE");

   This will cause the window to remain open until you hit any key.
2. Extra final read. Put an extra read immediately before the return. Just ignore the input and return, but this stops the window from disappearing until there is input.
3. Console window. Open a command/console/DOS window, cd to the appropriate directory, and run the program "by hand" by typing the name of the .exe file.
4. Breakpoint. Set a breakpoint on the return statement at the end of main. To use the debugger:
   - Put the cursor on the return statement.
   - Click Debug instead of Run.
   - Choose Run to Cursor from the box that appeared at the bottom of the window. This runs your program until it gets to the statement with the cursor on it (the return statement), leaving the console window open. Note that the console window may be positioned under the source window so you will have to bring it to the top.
   - Click Continue in the bottom box to terminate the program. Sometimes you may have to click Stop Execution in that bottom box to get the debugger to let go.