"The greatest power of the mass media is the power to ignore. The worst thing about this power is that you may not even know you're using it." --Sam Smith
#inlcude Is an add-on for you programs needs. one of the main ones in C++ Is <iostream>. If you learn C++ Thoroughly you will learn the commands you will need for you program. The syntax for the command is very simple:
CODE :
#include <iostream>
Using namespace std;
Now Once you have written the #include <iostream> you will need to add a command which tells the compiler that you are writing in C++. Something you mayu notice different is the semi-colon, You should use a semi-colon after every statement you make, It simply tell the program to move on form this statement and go to the next on in the program. Again the syntax for this part is very simple:
CODE :
using namespace std;
The Bulk Of The Program
Now is the time to make the program.This is were the main() Command comes into position. The main part of the program goes after this command. This is were all of the program comes together. Yes you can add things before that command but i will come to that if this article is succesful. In this command you will be intoduced (If you havent used them before) to the braces. Which look like this: {}. This is were the code is stored. That may have confused you but it is very basic once you see the syntax, Which is shown below:
CODE :
main()
{
code goes here
}
Return Statement
The return statement is again very simple. All it does is return a value to the operating system. Their isnt much to this statement although it can be quite important when writing certain programs. Here is the syntax for the return statement:
CODE :
return 0;
Once you learn more C++ you wont always have the 0 their. In C++ 0 is just another way of saying null. Also notice i have used the semi-colon. this is because it is a statement.
Writing a program
Now we have learnt all of the basic commands maybe we can write a very simple and traditional hello world program. This include another statement which i have saved until now, It is the cout << statement this is another word for print. Also this is another statement so the semi-colon is used. Here is the sytax for that:
CODE :
cout<<"text goes inbetween the speech marks";
Back to the program.
CODE :
#include <iostream>
using namespace std;
main()
{
cout << "hello world";
cin.get();
return 0;
}
The output is simply:
CODE :
Hello world
If you liked this artricle then please post and leave a good number please thanks
Cast your vote on this article 10 - Highest, 1 - Lowest
Comments: Published: 25 comments.
HackThisSite is the collective work of the HackThisSite staff, licensed under a CC BY-NC license.
We ask that you inform us upon sharing or distributing.