So if you open
up code blocks you’re going to want to click on Create a new project and then
console application on mine it’s in the top right corner of the
window on yours it may be different but you want to click on console
application and then hit go then on the next window you want to hit next
until you get here.
Make sure you highlight C++ click Next again and then give your
project a name and man I’m just going to call it Tauriel wind and then
specify a folder to keep it in.
Make sure it’s a folder that you can
find easily and then click next. Leave all the default settings on this
window right here. These are simply directory and compiler settings.
Just hit thinnish and then your project is created.
So right now you don’t see anything but if you go over here to the
left and click on sources you’ll see the main does the file which stands
for main dot C plus plus.
And if you double click it you’ll see the code.
Now before we analyze this code I want to go ahead and show you how to run it
and what this code does and to do that on Windows you can either hit F 9
or if you’re on a Mac or Linux machine you can just go up here and hit
build and build and run.
The code will compile and then you’ll see this console window.
It prints the word hello world and then says Process returned 0.
OK so you can close up of this.
Now that we know what the code does is we’re gonna look at how this
code is what it is. So beginning with kind of the main thing I want to
show you in this tutorial other than you know how
to run your first
program and compile it is you know how to type out the skeleton of a C++
It’s what I call the skeleton and it’s everything that you need for
your code to run at least in this course any ways for every program that
we will be writing together.
So if we go ahead I want to go ahead and take out this line because
this line is not actually needed for this program to compile and run.
So if we take it out and we hit F 9 and we build and run it again
we will get the processor turned to zero.
We just won’t have
hello world printed to the console which means I mean that’s fine.
The program just ran and executed till it finished with no errors.
And it’s a perfectly good program. So if we exit out of this
we’re going t o now analyze everything that we need which is everything that
you see right here. So starting from the top you’re going to see pounde
include IO stream this lot of code right here just simply tells the
program that it needs to include a C++ library known as i o stream which stands
for input output stream.
Now on every program that we write you will need this line of code
which is why I include it in our skeleton is because you know if you
don’t have this line of code your program will lose its basic input
output functionality. So you do need this line of code and every program
that we write. Moving on you’re going to see using namespace standard.
Now this line of code is not necessary for your program to run.
OK so if we
took this code out right now it should still run fine.
We hit F NAND.
Everything goes fine and we still get the same result process returns 0.
However I do want this line of code in here for reasons that I’ll explain in
For now just know that we do want to include it as part of our
skeleton because it will make your life easier when we start writing
more code and I will show you on future tutorials.
But for now just know that you do need using namespace standard
And it does it with the semi-colon on. Right now you’re
saying why does this line of code end with a semi-colon and this one doesn’t.
Well we’ll get to that in future. Toils again.
It’s all going to become a habit. For now just know this.
This is the code that you will need in all of our C++ programs. Moving
on to the next big chunk of code. This right here is known as your main
function and in every C++ program that we write you will need a main
function and type it up. You just simply write I continue which stands
for integer and then main open print close parentheses and then your
brackets with the return 0 statement.
Now in in programming there’s two different conventions for writing
these brackets I want to go ahead and show them to you now so you don’t
Later if I do this one convention is the way I just saw it
which is like this where your brackets are open and closed down here.
But the other way you may see it is like this where your brackets open
at the top and close down there which is fine there is no difference in the
code whatsoever it will run just the same. So I just know that it’s it’s
just a programming convention.
There’s no right or wrong way. Some people have their own
opinions on why they do it a certain way but just know you know it’s all
a matter of preference. So before we end this tutorial on when you go
through and I want you to top this up with me so you can get in the
habit of doing it. So what’s the first thing we need to do.
What we need to include the input output string C plus plus
libraries so we can you know output stuff to the console window to do
that we’re going to hit pounde include IO stream.
Ok no semi-colon on
this line again.
He’ll get in the habit of no where to put him where not to put him.
But for now you know just no there’s no semi-colon at the end of this line.
Now though we don’t need it for this program. You do one is part of your
skeleton for this class Id want you to get in the habit of writing it and
all of our programs.