Stuyvesant Computer Programming Club
Basic Input/Output Streams
Home
Lessons
Topics Covered
Club Policies
Links
Contact Information
Downloads

Beginning your first C++ program

The first thing to do when you start a language is to get accustomed to a compiler and have a working program, no matter how little it does.
 
If you choose to use the Dev-C++ compiler (you can download from the links section), then heres how to set up your first C++ program. If you are using another compiler, scroll down.
 
The following program does one simple thing, it prints the message "Hello world"
 
Open Dev-C++. Go to file > new > source file.

CompProgClub3.gif

Now type in the following code:
 
#include <iostream.h>
#include <iomanip.h>
int main()
{
    cout<<"Hello World"<<endl;
    return 0;
}
 
I will explain this code later. Be careful with the spaces and punctuations, they are important in C++. For now, just copy and paste this code.
 
Now save it by going to file > save. Next, you need to compile the code, which means that the compiler (in this case Dev-C++) turns your code into an program that does something. You can do that by going to execute > compile or press the button circled in the diagram below.

CompProgClub4.gif

To run your program, go to Command Prompt (every windows systems should have one). If you can't find it, go to Program > Accessories > Command Prompt. Go the directory you saved your C++ file in. If you did everything by default, it should be in the folder dev-cpp. So type cd dev-cpp. Command line arguments (what you type into the command prompt) are case-sensitive and space-sensitive. Therefore, watch out when you type these things. Then type the name of your program (what you saved your C++ file to be). In my case, I named my file CompProgClub1. Thus I just type CompProgClub1 and it should print Hello World, as in the following diagram.

CompProgClub5.gif

If you are using a different Compiler:
If you are using something like Borland's C++ or Microsoft Visual C++, then the library files are probably incompatible with the ones used in this club. Therefore, if you do use those compilers, please email me or ask me during the club meetings, and I will give you the library files.
 
If you can't get the program to work:
Please email the president or vice president or ask during the club meetings and they will resolve your problems. You can also use a different program, Putty.

Screenshots taken by me, the prez. Editted with Adobe Photoshop(R) 7.0

Enter supporting content here