We need to install an IDE and a compiler before we can write C++ programs. An IDE, or integrated development environment, is a piece of software with tools for writing programs. We will use the Code::Blocks IDE for these tutorials, because it's free and it works on a variety of operating systems. You can use other IDEs to complete the tutorials on Text Game Tutor, but remember that some of the features in your IDE may differ from the ones in Code::Blocks. We will also need a compiler, which translates code written in programming languages—like C++—into the machine code that computers use. We will download a Code::Blocks version that already includes a compiler.
Note: These installation instructions are written for Windows users. If you're using a Mac, you can follow the instructions in this video tutorial for installing Code::Blocks on a Mac by jburt1992.
Part 1: Installing Code::Blocks on Windows 2000/XP/Vista/7
What You Will Need
- A computer with Windows 2000, XP, Vista or 7.
- An account with administrator rights that allows you to install programs.
- A copy of these instructions printed or memorized, because you will have to close your browser during the installation process.
- 15 minutes.
- Go to the Code::Blocks download page.
- Download the Code::Blocks version labeled "codeblocks-12.11mingw-setup.exe."
- Close any applications you have open and run the file.
- Keep all of the default options in the installer.
- Run Code::Blocks to write your first C++ program.
Part 2: Setting Up The File for Your C++ Program
- Choose "Create a New Project" in Code::Blocks
- Choose "Projects" -> "Empty Project."
- Click "Next"
- Enter "HelloWorld" as your project title.
- Click the "..." next to the "Folder to create project in" window and create a new folder for your program.
- Click "Next." If you're on Windows, make sure that "GNU CCC Compiler" is selected before clicking "Next" again.
- Choose "File" -> "New" -> "Empty File." Choose "Yes" for the prompt that appears.
- Name your file "HelloWorld.cpp" (include the quotation marks if you're using Windows) and click "okay" on the prompt that appears.
Part 3: Writing Your First C++ Program
- Write the following code on the first line of the file.
#include <iostream>
- Write the following code on the second line of the file.
using namespace std;
- Write the following code on the next line.
int main()
- Add a "{" (an opening brace) on the next line. Code::Blocks will automatically add a "}" (a closing brace) for you two lines down.
{
}
- Write the following code on line 5, between the opening brace and closing brace.
cout << "Hello World" << endl;
- Add an empty line after the last statement you added.
- Write the following code on line 7
return 0;
- Choose "Build" -> "Build."
- Choose "Build" -> "Run," if no errors were generated in Step 8.
Congratulations! You just wrote your first C++ program. If your program had errors, I've included the entire program in
this Google Drive file so you can check your code against mine. In the next tutorial, we'll discuss what each line in this program does, and then expand our program to use input from a user.
No comments:
Post a Comment