// HELLO WORLD!
#include <iostream>
using namespace std;
int main()
{
// Comment
cout << "Hello World!"<< endl;
system("pause");
return 0;
}
if you run this then you get this window.
now to go throught and explain the code(its so simple)
#include <iostream>
this is a preprocessor statement signified by the '#' , it tells the compiler to "include" the file "iostream". which stands for Input/Output stream , we have to add it to use the "cout" statment.
using namespace std;
this tells the compiler that we are "using" the namespace std, it just makes it easier to use "cout" statements . for example , if we didnt put it in then we would have to use cout like this = std::cout <<"Hello World!"<<endl;
int main()
{ }
now this is out "main" function , all the code inbetween the braces "{ }" is what gets compiled and executed, the "( )" show that main is a function , and the "int" before it just means that it "returns"(ill talk about that later) an integer value.
// Comment
This is how you put comments in your code , the double "//" signify that everything after them (on the same line) is a comment , and the compiler will skip over it.
cout << "Hello World!"<< endl;
Now this is the actual code that outputs our text "Hello World" to the screen. there is also a cin statement , which gets text from the user . so cout and cin(we will use cin later) write and read text to and from the screen. the "<<" just means that the following text is being "cout-ed" , to signify text you have to enclose it in double quotes like this "This is txt". and again the "<<" followed by an "endl" which stands for "ENDLine" and that is what it does , it is like pressing enter when typing , it moves down to the next line.
i probably should have mentioned this in the beggining , but ill do it here , all statements in C++ must end in a semicolon ";" it tells the compiler that the line of code has ended. Also the compiler is the thing that turns your code into code that a computer can understand, its run when you press the ">" run button (in Visual Studio) on your IDE(visual studio and codeblocks are examples of IDE's).enough of that lets move on.
system("pause");
You may not need this , but for me (using vista) if i run the program with out it the console window just flashes and closes , this will "pause" the execution of your program until you press any key(which it says on the console window).
return 0;
this is what your "main()" function returns , which is 0(zero) , this signifies that the program exited/ended normally . without it the compiler would complain.
and like i said before all the code goes between the { },and so our program is done.
i know its not the best looking thing but its a start.
that was pretty indepth if i do say so myself :) , now for people to read it (if there will be any , oh well :D)
No comments:
Post a Comment