Join Peggy Fisher for an in-depth discussion in this video Exploring the IDE, part of Learning C++ (2014).
After you clicked Open Eclipse, you will see a prompt for the default work space. Click the check box and then click OK. If we are using Eclipse for other programing languages, such as Java or Python, we might have to change the prospective. In the top right hand corner, you'll see, right now, I have the CC++ prospective checked. The main part of the window will be empty the first time we open the prospective. On the left, there will be a block containing the Project Explore. This is where we'll see all of our projects and program files.
Let's take a look at the menu bars on the top. The Standard Menu tool bar contains the File > Edit > Source > Refactor > Navigate > Search > Project > Run > Window and Help. Right below that toolbar, are some of the often used icons, such as the Hammer for building a new project icon, a new Source File, the Save Option > Save All > Print > Build All > Run, and more.
Before we start, it might be helpful to create a code template that we can use for the duration of our course. This will be helpful when we go to Create New Programs. So let's go to Window Preferences. On the left-hand side, you'll see C, C++, expand that, go down to Code Style, expand that, and then go to Code Templates. Under Files, if you expand files, you'll see C++ Sourcefile.
Click on that, and then let's click New. We're going to give this a name. We're going to to call it C++ with mean. And the description of this is going to be a template that contains RC++ program. The pattern section is the part that will always show up when we create a new Source File, using this template. So let's start with the pattern by adding a comment, a multi-line comment that we'll talk about more.
But it begins with slash asterisk. In the multi-line comment, I'm going to use the Insert variable, to allow me to add the file name. Below that, I'm going to insert the date, and below that, I'm going to insert the author. So all of these values will get inserted automatically. In C++ it's called The User. I'm going to end that comment, and right below that, I'm going to add some more template code. So we want to type in Pound sign, Include.
Less than sign, iostream. The iostream. This line of code is one we'll want on all our programs. Hit Enter, and type in using namespace, std. And we'll use the standard namespace in most of our programs. Below that, we're going to type in int main. This is the starting point for our programs, and all our code will be enclosed in an open curly bracket, and I'm going to put one more comment to make sure I remember that this is where I want to put in my new code.
So I'm going to say, place code here. I'm going to add one more thing. Since most of our programs will end with a value of 0, I'm going to go ahead and say return 0. This indicates a program ended correctly. And I'm going to do a closed curly bracket. This will save us a lot of typing as we go through these exercises. Let's click OK, and click OK again. Now that we created the template, let's go ahead and create a project and use the template to create a new C++ source file. So I'm going to go to File > New > C++ Project and I'm going to call it Greetings.
Under Project Type, I want to choose Empty Project and under the Toolchains, the Toolchain is what we installed from the equation.com website. We want to choose minGwGCC. And I'm going to click Finish. Now I have the project created, but I still need to create my Source File. So again, let's right click on Greetings and go to New, and let's go down to C++ Source File. You'll notice that mine came up with a template of C++ with main automatically.
If you don't see that, click on the down arrow and scroll down until you find your C++ with main. Let's call this one Greetings, and don't forget to add the .cpp. The .C++ extension, or your program will be saved as a notepad file instead of a program file. I'm going to click Finish, and you can see that here is everything that we had added. If I click on the plus sign next to the two, it'll expand this section. So I'm going to do that, and it says greetings.cpp is the name of our program.
The date we created it was May 20th, and the username. In my case, peggyfisher. I can use the minus sign to minimize that, so I don't have to look at that when I'm going through my entire code. You can also see that it automatically headed our pound sign include iostream, our using namespace std, our int main, our open curly bracket and our comment for where we're suppose to place our code. Okay, for this first program, we're going to go ahead and replace the comment that we have here, going to take that out, I'm just going to delete that.
I'm going to to tab over, and I'm going to actually write something to the screen. The way that we do that, is we use the command C OUT, C out. Two less than signs, which is actually called the Insertion Operator. Double quotes, and in double quotes, I'm going to put myMessage. So I'd like to say hello and welcome to Up and Running with C++.
Okay? And then at the very end, I'm going to do less than, less than again and ENDL semicolon. We'll talk about some of this Syntax as we go through some of our other programs. Okay, at this point, that's all I needed to do. I can go ahead and build this, to make sure that I don't have any compile errors. So I'm going to go up to my hammer, I'm going to click on the hammer to build the project. On the bottom, in the Console window, you can see it says the build finished, it even tells me how long it took. And there's no errors or warnings, so I'm good.
Now I'm going to go ahead and Run this first program, this Greetings Program by clicking on the green circle with a white arrow in the middle, it says Run. Okay, I got a message saying greetings.cpp has been modified. Do I want to save the changes? I'll say Yes. And now the message in the Console window's changed. It now says Hello, and Welcome to Up and Running with C++. It looks like our program worked. Awesome. If you don't see the Console window on the bottom, it might have been accidentally closed. But we can open it by going to Window > Show View > Console.
This is helpful in case you accidentally close the Console window. Well that was our first program. Good job.
- Downloading and exploring the C++ IDE
- Working with loops
- Using predefined functions
- Creating custom functions
- Creating and instantiating classes
- Working with external files
Skill Level Beginner
Q: How do I upgrade the C++ compiler on Mac OS X and Linux?
A: Refer to C/C++ Essential Training for a detailed look at installing or upgrading the C++ compiler on various platforms.
Q: The link to download the Eclipse IDE in the "Download a C++ IDE" movie doesn't work. Where can I find the IDE?
A: Short URLs are case sensitive and need to be typed in exactly as they appear. Type in or simply click http://goo.gl/CzckWp to visit the Eclipse IDE for C/C++ Developers page.