Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
24 views

DevCppTutorialGraphics H

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

DevCppTutorialGraphics H

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

11/25/11 De -C++ T ia f CSC 161 S de

Dev-C++ Tutorial for CSC 161 Students (Maintained b


Michael Serrano)

Update (9/12/2006):
I ' bee ie e i e i ce I' e da ed hi age; i fac , I ac f i f a hie. I he h e ha i a
i be ef , I' e da ed hi ia be c e i h he a e e i f De -C++ (a f hi i i g,
Ve i 5 Be a 9--a. .a. Ve i 4.9.9.2). Mike

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 e-
ba ed C/C++ ga i g he Mi GW c ie e . Click pic re o enlarge.
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 .

*GNU i a ec i e ac on m fo "GNU' No Uni "; i i


p ono nced "g h-NEW". The GNU P ojec a la nched in 1984
o de elop a f ee and comple e Uni -like ope a ing em.

Bloodshed!?
I' be he fi a ha he a e B d hed ' gi e a a df ie , b I hi i ' be if he c ea
f B d hed e ai :

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

. i 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++ ( GPL) CD
B ( ' ), D -C++ / .

L B D -C++ D -C++ .

Y D -C++ C:\D -C ,
- .

U ing De -C++
T .

A CSC161 (. . ( ),
() / / / ). T
D -C++ .

S ep 1: Config e De -C++.
W .

G "Tools" "Compiler Options".


I "Settings" , "L " , "Generate debugging
information" "Yes":

C "OK".

S ep 2: C ea e a ne p ojec .
A" "
.

G "File" "New", "Project...".


C "Empt Project" "C++ project" .
H .Y ,
.
O , "OK".
D -C++ .

. i e e -e a e.c /de c /# e 4 2/7


11/25/11 De -C++ T ia f CSC 161 S de

Step 3: Create/add source file(s).


Yo can add emp o ce file one of o a :

Go o he "File" men and elec "Ne Source File" (o j p e CTRL+N) OR


Go o he "Project" men and elec "Ne File".
No e ha De -C++ ill no a k fo a filename fo an ne o ce file n il o a emp o:
1. Compile
2. Sa e he p ojec
3. Sa e he o ce file
4. E i De -C++

Yo can add p e-e i ing o ce file one of o a :

Go o he "Project" men and elec "Add to Project" OR


Righ -click on he p ojec name in he lef -hand panel and elec "Add to Project".

EXAMPLE: M l iple o ce file

I hi e a e, e ha 3 fi e a e e i ed c i e he g a ; The "d i e .c " fi e


efe e ce "De e.h" ( hich e i e "De e.c ") a d "De e.c " efe e ce "Q e e.h" ( hich
e i e "Q e e.c ").

Step 4: Compile.
Once o ha e en e ed all of o o ce code, o a e ead o compile.

Go o he "E ecute" men and elec "Compile" (o j pe CTRL+F9).

I i likel ha o ill ge ome kind of compile o linke e o he fi ime o a emp o compile a


p ojec . S n a e o ill be di pla ed in he "Compiler" ab a he bo om of he c een. Yo can
do ble-click on an e o o ake o o he place in he o ce code he e i occ ed. The "Linker"
ab ill fla h if he e a e an linke e o . Linke e o a e gene all he e l of n a e o no
allo ing one of he file o compile.

Once o p ojec cce f ll compile , he "Compile Progress" dialog bo ill ha e a a of "Done". A


hi poin , o ma click "Close".

Step 5: E ecute.

. i e e -e a e.c /de c /# e 4 3/7


11/25/11 De -C++ T ia f CSC 161 S de

Yo can no n o p og am.

Go o he "E ecute" men , choo e "Run".

No e: o pa command-line pa ame e o o p og am, go o he "E ecute" men , choo e "Parameters"


and pe in an pa ama e o i h o pa .

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 ill gi e o a chance o ie an o p befo e he p og am e mina e and he indo clo e .

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.

Dev-C++ User F.A.Q.


Wh do I keep getting errors about "cout", "cin", and "endl" being undeclared?

. i e e -e a e.c /de c /# e 4 4/7


11/25/11 De -C++ T ia f CSC 161 S de

I ha o do i h name pace . Yo need o add he follo ing line af e he incl de of o implemen a ion (.cpp)
file :

ing name pace std;

Ho do I use the C++ string class?


Again, i p obabl ha o do i h name pace . Fi of all, make e o "#incl de < ing>" (no ing.h).
Ne , make e o add " ing name pace d;" af e o incl de .

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;

Ho do I use Borland Graphics Interface (graphics.h)?


Fo ho e of o mig a ing f om Bo land, o ma be onde ing he e g aphic .h i . Unfo na el , g aphic .h i
a Bo land pecific lib a and canno be ed i h De -C++. Fo na el , a bene olen o l b he name of
Michael Main ha modified a BGI em la ion lib a fo Windo applica ion o be ed nde MinGW (and
he efo e De -C++) hich he ha ap l named WinBGIm.

The file e need a e:

g aphic .h (do nload o C:\De -Cpp\incl de)


libbgi.a (do nload o C:\De -Cpp\lib)

Af e o ha e do nloaded he file o he co ec loca ion , o can no e WinBGIm' g aphic.h a o


o ld Bo land' g aphic .h i h a fe ca ea .

Using librar files:


Fi , o ha e o ell De -C++ he e o find he lib a f nc ion ha WinBGIm efe ence -- hi i done in he
"Project Options" dialog bo .
He e a e in c ion on ho o do hi i h a ne p ojec :

Follo ep 2 and ep 3 of "U ing De -C++".


Go o "Project"men and choo e "Project Options"(o j pe .
ALT+P)

Go o he "Parameters" ab
In he "Linker" field, en e he follo ing e :
. i e e -e a e.c /de c /# e 4 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.
. i e e -e a e.c /de c /# e 4 6/7
11/25/11 De -C++ T ia f CSC 161 S de
4/16/2001:
Fi ed e i i bgi .h (c i .h c fic ).

3/23/2001:
U da ed Wi BGI 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 ea (i fac , I e A e' Xc de), b if ha e a
e i , fee f ee e ai e a eb a e @ i e e - e a e.c

Ha c di g!

Copyright 2006 Michael Serrano.


La Modified 3:13 PM 9/12/2006

. i e e -e a e.c /de c /# e 4 7/7

You might also like