http://cpp.gantep.edu.tr
C++ resources. Faculty of Engineering, University of Gaziantep
 MAIN  -  Tutorials  -  Howtos  -  nmPrimer  -  Misc  -  Links  -  Contacts
Last modified: Sun, 01 Nov 2009 12:49:44 +0200
Howto: Compiling with the Dev-C++ compiler (under Windows)

In this how to, compilation of C++ sources will be demonstrated using the Bloodshed Dev-C++ compiler under Windows.

1.   What is Dev-C++
2.   How to download Dev-C++
3.   How to open and compile a C++ source file with Dev-C++
4.   Disappearing Windows
5.   F.A.Qs

1.   What is Dev-C++

Dev-C++ is a full-featured Integrated Development Environment (IDE) for the C/C++ programming language. It uses Mingw port of GCC (GNU Compiler Collection) as its compiler. It creates native Win32 executables, either console or GUI (Graphical User Interface). Dev-C++ can also be used in combination with Cygwin.
More information can be found at The Dev-C++ Resource Site.


2.   How to download Dev-C++

You can use the following links to download the program (9 MB):


3.   How to open and compile a C++ source file with Dev-C++

After you download and install Dev-C++ (under default folder C:\Dev-Cpp), you can open a new (c++) source file as shown in the figure given below:

Then type your c++ code and save it to the hard drive (for example C:\windows\desktop\cpp).

To compile your source file (say hello.cpp), press Compile button or use Ctrl+F9 key combination.
To run the compiled (executable) file press Run button or use Ctrl+F10 key combination.
Note that executable file will have the name hello.exe and it would be in the same folder with the source file hello.cpp.

4.   Disappearing Windows

If you run your program, you may notice something stange; a console window will pop up, flash some text and disappear suddenly. The problem is that, if directly executed, console program windows close after the program exits. You can get around this problem one of three ways:
  • Method 1
    Add the following code before return 0; statement in main():
    system("pause");
    This will give a message such as Press any key to continue.... After pressing a key, you can return to the compiler editor.

  • Method 2
    Add the following code before return 0; statement in main():
    // Scaffolding code for testing purposes
    cin.ignore(256, '\n');
    cout << "Press ENTER to continue..." << endl;
    cin.get();
    // End Scaffolding
    
    This will give you a chance to view any output before the program terminates and the window closes.

  • Method 3 - Command-prompt:
    Alternatively, instead of using Dev-C++ to invoke your program, you can just open an MS-DOS Prompt, go to the directory where your program was compiled and enter the program name (along with any parameters). The command-prompt window will not close when the program terminates.
See also: www.uniqueness-template.com/devcpp

5.   F.A.Q.s

Q. How can I add line numbers?
A. Goto Tools Menu and follow: Tools->Editor Options. Click on the Display tab and then select Line Numbers.
 


Q. Can I compile and run my programs in the MS-DOS console?
A. Yes, you can compile and run your codes in the MS-DOS console without using compiler editor.
But first, you have to play with the environment settings. To do that, go to Settings->System->Advanced (Denetim Masası->Sistem->Gelişmiş). And click on the Environmental Variables button. Click on the PATH and modify by adding C:\Dev-cpp\bin\ string as follows, then press OK.


Now you can open an MS-DOS propmt. Go to Start->Run (Başlat->Çalıştır). Type cmd to open a console. Goto the directory where your programs exist. Compile and run your program (for example hello.cpp as here) as follows:

please send us you comments/questions/corrections