EECS 311: DATA STRUCTURES

Dev-C++ Notes

Dev-C++ is a free integrated development environment (IDE) for C and C++ on Windows. There are many such environments, such as Microsoft Visual Studio and Codewarrior. Any IDE can be used for this course. Most are quite similar to each other. We'll use Dev-C++ in the class examples.

Dev-C++ can be downloaded from here.

System requirements

Dev-C++ requires Windows. You need about 9 megabytes for the download file and 60 megabytes more for the installed IDE.

Install Dev-C++

The instructions below should be enough to get you going. After you've installed, if you run into problems, check Aditsu's unofficial Dev-C++ FAQ.

Just to be safe, avoid using folders and file names with spaces. Don't install things in My Documents or similar. Put Dev-C++ in a simple location, such as C:\Dev-Cpp. Put your EECS 311 code in a simple location, such as C:\Courses\EECS311. Don't put your own code inside the Dev-C++ folder. You may lose your work if you have to reinstall Dev-C++.

Install the EECS 311 Template

Download the EECS 311 archive. This is a Zip archive file that contains compressed (smaller) versions of other files. Windows XP has built-in support for getting files out of Zip archives. If you have an older Windows, you can use WinZip or FilZip or any of a number of inexpensive or free Zip archive utilities.

Put the files in the archive into the folder C:\Dev-C++\Templates\. (Modify this path if you put Dev-C++ somewhere else.) In Windows XP, you can just copy and paste, or drag and drop, the files in the archive to the Templates folder. If you're using a utility, use the Extract command.

Create An EECS 311 Project Directory

Create a folder (directory) in Windows where you will keep all your code, e.g., C:\Courses\EECS311\Code.

Start Dev-C++.

In Dev-C++, click on the Tools menu and select the Environment Options menu option.

Click on the image to enlarge it.

Dev-C++ environment options menu

The Environment Options dialog box will appear. Click on the tab labelled Files & Dir.... To tell Dev-C++ to always start looking for files in your EECS 311 directory, click on the small "folder selector" icon next to User's Default Directory field. This will open a file dialog box that will let you navigate to and select your code directory.

After you have found and selected your directory, click Ok to choose it, then click Ok again to close the Environment Options dialog box.

Click on the image to enlarge it.

Dev-C++ default directory dialog

How to Create a Project

In Dev-C++ and most other development environments, you create a project for each application you build. A project is a small file that lists the code files needed to make the application, plus various settings for compiling those files. The steps below show how to create a project in Dev-C++. Other IDE's are very similar.

The simplest kind of project to build is one that does all its input and output in a console window, e.g., the Command Prompt window in Windows. Such programs are simple to set up, but are a bit old-fashioned.

Start Dev-C++, click on the File menu, then on New, then on Project ....

Click on the image to enlarge it.

Dev-C++ new project menu

The New Project dialog box will appear.

  • Click on the Introduction tab.
  • Click on the icon that says EECS 311 Console.
  • Enter a name for this project, e.g., PA1 for Programming Assignment #1.
  • Click Ok to create the project.

Click on the image to enlarge it.

Dev-C++ new project dialog

Dev-C++ will ask where you want to save the project. If you set the default directory correctly, you should already be in your EECS 311 code directory. Click on the "new folder" icon to create a new folder, give the folder a name, e.g., the same name as your project, wait for Windows to create the folder, then click the Open button to open that folder. Save the project file and all code files in this new folder.

The project file will have a .dev extension. You can double-click that file in the future to reopen your project from Windows.

Click on the image to enlarge it.

Dev-C++ new project dialog

Now you should see a project screen. The name of your project should appear in the Project Browser on the left. The template automatically creates a file main.cpp for this project. (The extension .cpp means "C plus plus." Always use this for your C++ files.)

By default, this file is just a simple "Hello, World" program. For many assignments, all you'll need to do is edit this file.

Click on the image to enlarge it.

Dev-C++ empty project screen

Now you can type code into this window, save it, and compile it.

For illustration, I've typed in the code for Fig 1.10 from Chapter 1 of Weiss' Data Structures and Algorithm Analysis in C++. Note that the Dev-C++ editor knows about C++ syntax, and has colored different kinds of code differently. It also knows how to indent code. Let the editor do the work. Trust it. If something indents where you don't expect, or doesn't have the color you expect, you probably typed something wrong.

Click on the image to enlarge it.

Dev-C++ sample code file

To compile and run your program, the obvious choice is to select Compile & Run from the Execute menu, but even simpler, once you learn where it is, the Compile & Run icon.

When you do this, Dev-C++ will ask you where you want to save the code file and what name to call it, if the file hasn't already been saved. You can call the file anything. I called mine PA1 and saved it as main.cpp in my EECS 311 code directory, because this is the file with the main() function.

Click on the image to enlarge it.

Dev-C++ compile file

Ooops! When I clicked the Compile & Run icon, I saw a dialog box appear indicating that the code was being compiled, and a window flashed by, but I didn't see any input. What happened?

What happened was that Windows opened a Command Prompt window, ran my code, and then, because the program was done, immediately closed the window. This is a common "gotcha" with Windows. It's one of the FAQ's in the Dev-C++ Help material. The trick is to make Dev-C++ stop our program just before it calls return at the end.

To do that, put your cursor in the gutter area left of the line with the return 0 and click to set a breakpoint. A red icon should appear.

Click on the image to enlarge it.

Dev-C++ run with wait code

Now click on the purple Debug check mark at the top of the screen. This runs the program in Debug mode so it pauses when the line with the breakpoint is reached. The window with my output will open until I return to Dev-C++ and click Continue.

Note: the console window might appear behind the Dev-C++ window. Just move things around to see it.

Click on the image to enlarge it.

Dev-C++ run with wait code

Valid HTML 4.01 Strict