Hello, welcome to c++ lesson 1. In this lesson, you will learn basic outputs using the standard library in Code Blocks.
Installation
I won't bore you too much with this as I doubt you need a step by step on how to install a program its simple.
First, go to
this link and click on the download that says "Source Code". Open the download and go through
the setup. Just click next and finish until you get to the end and you have Code Blocks on your desktop.
Setup
Once the Code Blocks app is on your desktop, you are going to want to run it. Once you run it you will be greeted
with a project startup page. Now you will click "New Project".
After you double click that another page will pop up and in the top right you will see this Icon and double-click it.
AFter you have done that you will be greeted with yet another page. Just click next on it and on the next page click C++ and next.
After you do this name your project Lesson1 C++ and save it to wherever you want. AFter that ignore the pop-up page and click
finish at the bottom right.
Coding
Then you will be in the program ready to code. You are going to want to click a code blocks logo to the left then when it highlights blue below it click main.cpp
Now you there will be some code.
Highlight and delete all of the code in the box and write this code.
c++ code:
#include <iostream>
using namespace std;
int main ()
{
cout << "hello world" << endl;
return 0;
}
You may be asking what do all of these things mean? Well let me explain to you.
#include <iostreams> includes functionality to read and write from streams. You need to write this if you want to use streams.
it is basically a bunch of code written into a small key phrase so you do not have to manually enter codes.
using namespace std; is mandatory to use <iostream> cout, cin and a lot of other things are defined in it. So basically outputs and inputs are defined in it.
Std is standard you could also think of using namespace as a library and std a book with all of the codes in it.
so things like the keywords int are located in the std "book"
it is hard to explain but you will get it once you start to code a bit more.
I won't explain int main () very much until the next tutorial but int means integer.
cout << "hello world" << endl;
This whole line I am going to explain at once. Cout means it is being outputted to the screen. The << arrows are always represented after cout.
"hello world" is in quotes because it is what is going to be put on the screen.
Finally endl; means end line so your line doesn't fall into another part of the script. If you aren't getting it so far its ok there will be more explaining to these things in the next tut.
return 0;
Main function has to return a value because it is declared as "int main" which means "main function should return integer data type" if main is declared like "void main", then there's no need of return 0.
And yes that is the google deffinition. Its the best way to explain it you will understand this more later.
Now that you understand what all the terms mean it is time to see your script. Click the setup and run button at the top.
If you followed the steps correctly you would have had a cmd window come up that looks like this.
CONGRATULATIONS!
Stay open eyes for lesson 2 coming next week.
If you have any further questions please contact me using reply or pm me.