Basics to C++
If you are looking to learn C or if you already know C, It is recommended to learn C++. You don't have to know C to know C++ because C++ is just C but with more libraries and functions added on and has better interfaces than C. For this you will need a compiler for C++ and a recommended one is Code Blocks which you can get here http://www.codeblocks.org/. When you have it installed make a new console application.
Hello World
The hello world program is a widely taught program to beginners and I'm going to go the same way because it is a simple method that begginers will understand.
#include <iostream>
using namespace std();
int main ()
{
cout << "Hello World! \n";
return 0;
getch ();
}
main.cpp
That there is the hello world program. Test it on your compiler to see what it does. Then come back to the post and ill explain it.
-------------------------------------------------
Lets start with the first line of code.
#include <iostream>
This line is required in any program you make. the #include tells the computer that you are going to use a certain library of functions in your program. The <> is where you typed the named library in that you want to include, in this case we used <iostream>.
-------------------------------------------------
using namespace std();
This line of code is really useful to many programmers. It is not required but it lets you write you code in a easier format. If I wouldn't have included that line the rest of my code will have to be written out in words like so in the getch line.
get character none ();
-------------------------------------------------
int main ()
This line names you function. Usually a function named main is required in each program you make. The computer will look for it in an app you make.
-------------------------------------------------
{
}
Curly braces are required and they tell the computer when the function starts, and ends.
-------------------------------------------------
cout << "Hello World! \n";
The cout is a small function that outputs data for you in text. Using << tells the computer that data is going to be outputted. What ever you want to say you put in the parentheses. The \n is not required, but it just makes a new line as if you've pressed enter. (MAKE SURE YOU END EACH LINE OF CODE WITH SEMICOLONS).
-------------------------------------------------
return 0;
This function tells the computer how much extra data will be returned to the program.
-------------------------------------------------
getch ();
If you compile your program and the window that shows the program closes this is the function to use. It makes it so when the program finishes running it[ll wait for you to type a character before closing.
Any questions just ask!