Dev-C++ Tutorial For CSC 161 Students: Update (9/12/2006)
Dev-C++ Tutorial For CSC 161 Students: Update (9/12/2006)
De -C++ T
ia f
CSC 161 S de
Update (9/12/2006):
I ' bee
ie
e i e i ce I' e da ed hi age; i fac , I
i be ef , I' e da ed hi
ia be c e
i h he a e
Ve i 5 Be a 9--a. .a. Ve i 4.9.9.2). Mike
ac
e i
f i f a hie. I he h e ha i
f De -C++ (a f hi
i i g,
What is Dev-C++?
De -C++, de e ed b B d hed S f a e, i a f
fea ed g a hica IDE (I eg a ed De e
e
E i
e ), hich i ab e c ea e Wi d
c
eba ed C/C++
ga
i g he Mi GW c
ie
e .
Mi GW (Mi i a i GNU* f Wi d
) e GCC ( he
GNU g++ c
ie c ec i ), hich i e e ia he a e
c
ie
e ha i i C g i ( he i e i
e
g a f Wi d
)a d
e i
f Li . The e
a e, h e e , diffe e ce be ee C g i a d Mi GW;
i
Diffe e ce be ee C g i a d Mi GW f
e
i f ai .
Bloodshed!?
I' be he fi
a ha he a e B
f B d hed e ai :
d hed
' gi e
a df
ie , b I hi
i ' be if he c ea
First I would lik e to sa that I am not a satanist, that I hate violence/war and that I don't lik e heav
metal / hard-rock music. I am french, but I do k now the meaning of the "Bloodshed" word, and I use
this name because I think it sounds well. If ou are offended b the name, I am ver sorr but it would
be a big mess to change the name now.
There's also a reason wh I k eep the Bloodshed name. I don't want people to think Bloodshed is a
compan , because it isn't. I'm just doing this to help people.
Here is a good remark on the Bloodshed name I received from JohnS:
I assumed that this was a reference to the time and effort it requires of you to make these nice software
programs, a la "Blood, Sweat and Tears".
Peace and freedom,
Colin Laplace
e e -e
a e.c
/de c
/# e 4
1/7
11/25/11
De -C++ T
ia f
CSC 161 S de
Ge ing De -C++
T
D -C++
( '
B
L
(
),
D -C++
GPL)
D -C++
D -C++
D -C++
-
CD
C:\D -C
U ing De -C++
T
A
()
D -C++
CSC161
/
.
(. .
/
( ),
). T
S ep 1: Config e De -C++.
W
G
I
"Tools"
"Settings" ,
information" "Yes":
.
"Compiler Options".
"L
"
,
"Generate debugging
"OK".
S ep 2: C ea e a ne p ojec .
A"
"
.
G
C
H
"File"
"Empt Project"
"New", "Project...".
"C++ project"
.Y
.
,
.
O
D -C++
.
e e -e
a e.c
/de c
/# e 4
"OK".
.
2/7
11/25/11
De -C++ T
ia f
CSC 161 S de
o a :
o a :
hi e a
e,
e ha 3 fi e a e e i ed
efe e ce "De e.h" ( hich e i e "De e.c
e i e "Q e e.c ").
Step 4: Compile.
Once o ha e en e ed all of o
c
i e he
g a ; The "d i e .c " fi e
") a d "De e.c " efe e ce "Q e e.h" ( hich
pe
CTRL+F9)
emp o compile a
c een. Yo can
ed. The "Linker"
n a e o no
ill ha e a a
of "Done". A
Step 5: E ecute.
.
e e -e
a e.c
/de c
/# e 4
3/7
11/25/11
De -C++ T
Yo can no
n o
ia f
CSC 161 S de
p og am.
Disappearing indo s
If o e ec e o p og am ( i h o i ho pa ame e ), o ma no ice ome hing pec lia ; a con ole indo
ill pop p, fla h ome e and di appea . The p oblem i ha , if di ec l e ec ed, con ole p og am indo
clo e af e he p og am e i . Yo can ol e hi p oblem one of o a :
Method 1 - Scaffolding:
Add he follo ing code befo e an return a emen in main()o an e it()o abort() a emen
(in an f nc ion):
/* Scaffolding code fo e ing p po e */
cin.ignore(256, '\n');
cout << "Press ENTER to continue..." << endl;
cin.get();
/* End Scaffolding */
Thi
Method 2 - Command-prompt:
Al e na i el , in ead of ing De -C++ o in oke o p og am, o can j open an MS-DOS P omp ,
go o he di ec o
he e o p og am a compiled (i.e. he e o a ed he p ojec ) and en e he
p og am name (along i h an pa ame e ). The command-p omp indo
ill no clo e hen he
p og am e mina e .
Fo
ha i '
o h, I
e he command-line me hod.
Step 6: Debug.
When hing a en' happening he a o planned, a o ce-le el deb gge can be a g ea ool in de e mining
ha eall i going on. De -C++' ba ic deb gge f nc ion a e con olled ia he "Debug" ab a he bo om of
he c een; mo e ad anced f nc ion a e a ailable in he "Debug" men .
Using the debugger:
The a io fea e of he deb gge a e p e ob io . Click he "Run to cursor" icon o n
o p og am and pa e a he c en o ce code c o loca ion; Click "Ne t Step" o ep
h o gh he code; Click "Add Watch" o moni o a iable .
Se ing b eakpoin i a ea a clicking in he black pace ne o he line in he o ce code.
See he De -C++ help opic "Deb gging Yo P og am" fo mo e info ma ion.
e e -e
a e.c
/de c
/# e 4
4/7
11/25/11
De -C++ T
ia f
CSC 161 S de
ing.h).
E ample:
#include <iostream>
#include <string>
ing name pace std;
in main()
{
string s;
s = "This is a test";
cout << s << endl;
system("PAUSE");
e n 0;
e need a e:
e WinBGIm' g aphic.h a
e e -e
a e.c
/de c
/# e 4
pe
ALT+P)
5/7
11/25/11
De -C++ T
ia f
CSC 161 S de
-lbgi
-lgdi32
-lcomdlg32
-luuid
-loleaut32
-lole32
P ojec Op ion -> Pa ame e :
Click "OK".
Follow step 4, step 5 and step 6 of "Using Dev-C++".
BGI and WinBGIm diffe ence :
WinBGIm is a superset of BGI and as such ma have functions and features with which ou are unfamiliar. See
Michael Main's BGI Documentation for more information.
Te code:
Just to make sure ou've got ever thing set up correctl , tr this test code in a new Dev-C++ WinBGIm project:
#include <graphics.h>
int main()
{
initwindow(400,300); //open a 400x300 graphics window
moveto(0,0);
lineto(50,50);
hile(!kbhit());
//wait for user to press a key
closegraph();
//close graphics window
return 0;
If ou've done ever thing correctl , ou should get a simple graphic that closes when the user presses a ke .
Whe e i <
eam> ( ing eam )?
In previous versions of Dev-C++, the included compiler did not implement sstream. Fortunatel , new versions of
Dev-C++ do not have this problem. Upgrade to the latest version of Dev-C++.
Page cha ge l g:
/12/2006:
O e ha led page o be c
en
i h De -C++ 5 Be a 9 (4.9.9.2).
10/10/2001:
Added
eam info in FAQ.
.
e e -e
a e.c
/de c
/# e 4
6/7
11/25/11
De -C++ T
4/16/2001:
Fi ed e
i
i bgi .h (c
3/23/2001:
U da ed Wi BGI
i .h c
ia f
CSC 161 S de
fic ).
ced e .
3/21/2001:
S a ed FAQ ec i
i h
i g a d BGI i f .
3/1 /2001:
U da ed
i gi f .
3/16/2001:
Added
i gi f .
Tha ' i f
.
Ia
a De -C++ e e b a
e i
, fee f ee
e ai e a
Ha
ea
(i fac , I
eb a e @ i e e
e A
- e
e' Xc de), b
a e.c
if
ha e a
c di g!
e e -e
a e.c
/de c
/# e 4
7/7