Download and install Dev-C++
Go
here,
scroll down,
and download
“Dev-C++ 5.0 beta
9.2 (4.9.9.2) (9.0 MB) with Mingw/GCC 3.4.2”
from SourceForge.
- You have chosen to open
devcpp-4.9.9.2_setup.exe.
Save File.
- Please select a language.
English.
OK
- I Agree.
- Select the type of install: Full
- Destination Folder:
I simply agreed with
C:\Dev-Cpp
.
- Do you want to install Dev-C++ for all users on this computer?
Yes
- Your config files will be stored in
C:\Documents and Settings\winguest\Application Data\Dev-Cpp
Otherwise,
you can pass the following parameter to Dev-C++:
-c c:\config_file_directory
- Select your language: English (Original).
- Dev-C++ can retrieve information from header files.
Yes, I want to use this feature.
Yes, create the cache now.
- Close the annoying Tip of the day.
- File →
Exit
You have just created an application named
Bloodshed Dev-C++
containing the
GNU compilers
for C and C++.
Create and configure a Windows folder
Create a folder to hold the files of your program.
- To create the folder,
right-click on the desktop.
New → Folder
- Name the folder
hello.
- To see the filename extension
for each file that you put in the in the folder,
open the folder by double-clicking on it.
Tools
→ Folder Options…
→ View
→ Advanced Settings
Uncheck the check box labeled “Hide
extensions for known file types” (about halfway down the list).
Press the OK button at the bottom of the
Folder Options
window.
Download a one-file C++ program into Bloodshed
We will put the program into the directory we just created.
- Launch Dev-C++:
start →
Programs →
Bloodshed Dev-C++ →
Dev-C++
Close
the annoying Tip of the day.
- A
project
is the thing that holds all the files that constitute your program.
To create a new project to hold your program,
File →
New →
Project…
- In the
New Project
window,
make sure the
Basic
tab is selected.
Press the
Console Application
button.
Name the project
hello.
Press the
C++ Project
radio button.
Press the
Ok
button.
- In the
Create new project
window, where is says
Save in:,
browse to the
hello
folder that you created.
File name: hello.dev
Save as type: Dev-C++ project (*.dev).
Press the
Save
button.
- In the
Dev-C++ 4.9.9.2
window,
remove the existing
main.cpp
file from the project.
Do not bother to save it.
Project → Remove from Project
Select the file to remove from the project:
main.cpp
Press the
Ok
button.
Don’t save changes to
main.cpp.
- Point your web browser at
the first C++ program in the
in-class examples:
http://i5.nyu.edu/~mm64/INFO1-CE9264/src/hello.C
Save this file as
main.cpp
in the
hello
folder you created.
Then open the
hello
folder and
examine your
main.cpp
with
Wordpad.
It should look exactly like
this.
If the
<
characters in the original file were changed to
<,
delete the file and download it again.
This time, say
View → Source
in your browser,
and download the source as
main.cpp.
- Add the
main.cpp
file that you just downloaded to the project.
Project →
Add to Project
Select
main.cpp
and press the
Open
button.
-
Open the file
main.cpp.
File → Open Project or File…
Insert the statement
system("PAUSE");
before each
return
from the
main
function.
If your program does not have the statement
using namespace std;
you will instead have to insert
std::system("PAUSE");
File → Save
- Execute → Compile & Run
Hello, world!
This is an error message.
Press any key to continue . . .
- Before you “press any key to continue”,
right-click on the black window and
Select All.
You can then paste the entire content of the window into another
application.
Then press any key to continue.
You must close the black window
before you can run your program again.
-
If there are warnings (bad) or error messages (worse),
two things you can try are
Execute → Rebuild All
Execute → Program Reset
If you would rather compile your program by typing
a command line,
here is how to see the command line that Bloodshed uses to invoke the compiler.
Click on the Compile Log
tab at the bottom of the Bloodshed window
and look for the command line that starts with
g++.exe
.
On my machine (Windows Vista), the executable file
g++.exe
was in the directory
C:\Dev-Cpp\bin
.
Run the program from the Windows Command Prompt
After your C or C++ program has been compiled by Bloodshed,
you can also run it in the Windows Command Prompt without Bloodshed.
This will let you get teh program’s exit status,
and direct its standard output and standard error output
into files.
- start →
Programs →
Accessories →
Command Prompt
- cd to the
hello
directory that you created.
On my machine, the directory was
C:\Documents and Settings\user1\Desktop\hello.
dir
hello.exe
Press any key to continue . . .
echo %errorlevel%
0
- To direct the program’s standard output
and standard error output into separate files,
hello.exe > output.txt 2> errors.txt
Press any key even though you don’t see the “any key” message.
dir output.txt errors.txt
type output.txt
del output.txt
- To direct the program’s standard output and standard error
output into one file,
hello.exe > both.txt 2>&1
Press any key even though you don’t see the “any key” message.
dir both.txt
Tell the C compiler where to find the file cc1.exe
If your C compiler
(gcc.exe)
complains that it cannot find or execute the file
cc1.exe,
tell the compiler where to find this file.
- Discover where
cc1.exe
is.
start →
Search →
For Files or Folders… →
All files and folders →
All or part of the filename: cc1.exe
For example,
the file
cc1.exe
is in the directory
C:\Dev-Cpp\libexec\gcc\mingw32\3.4.2
on my machine.
- Add the directory to the list at
Tools →
Compiler Options →
Directories →
Binaries
Run the Debugger
- Disable class browsing:
it crashes the debugger.
Tools →
Editor Options →
Class browsing →
Uncheck “Enable class browser” and press Ok.
- Project →
Project Options →
Compiler →
Linker →
Generate debugging information →
Yes and press
Ok
- File → Save
- Execute → Compile
- Click
Debug
tab on the left,
Debug
checkbox below.
- Click on the left marin of your
cpp
file to set a breakpoint.
- Run to Cursor
to execute up to the breakpoint and stop.
- Add Watch →
Enter variable name.
You should see the variable’s name and value in the left panel under the
Debug
tab.
- Next Step
to go one statement forward;
or
Continue
to go to the next breakpoint or all the way to the end of the program.
The next line to execute is in dark blue.
When you reach the end of the program,
remember to bring the
“Press any key to continue…”
window to the front and press any any key.
A C++ program that calls functions written in C
(Chapter 1,
p. 86, Homework 1.7.3a)
- Create a folder and name it
term.
Create a project,
name it
term,
and save it in the folder.
- Remove the existing
main.cpp
file from the project.
Project → Remove from Project
- Using your web browser,
download the three source files from
Chapter 1,
pp. 85–89,
term.h,
term.c,
and
main.C.
Save them in the
term
folder,
saving
main.C
with the name
main.cpp.
-
Add the three files to the project.
Project →
Add to Project
- To tell the computer that the
term.c
file is written in the language C, not C++,
do the following.
Project →
Project Options →
Files →
term.c
Uncheck
Compile file as C++
and press the
Ok
button.
- In the
term.c
file,
uncomment the
#define MICROSOFT.
File → Save
- In the
main.cpp
file, insert the statement
system("PAUSE");
immediately before the statement
return EXIT_SUCCESS;.
File → Save
- Execute → Compile & Run