CoolManBob
07-02-09, 10:30 PM
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!\n";
return 0;
}
This is your basic Hello World Program.
This is usually the very first program people start out with when they begin doing
programming.
Im going to explain what each line does :)
#include <iostream>
# is a preproccessor symbol, you may have used it with #define, a preprocessor symbol tells
the compiler to do something before it starts compiling, in this case it tells the compiler
to find iostream.h and include it in this .cpp file.
When a compiler includes something, it means that the .cpp file can use functions that the
.h file declares.
using namespace std;
In programming there are things called Classes and namespaces, classes and namespaces are
similar to each other in that they both are a group of functions, but they are different.
Namespaces are a group of function identifiers, in this case std, this line tells the
compiler that the .cpp file is using the std namespace so every time a function has a std
identifier there is no need to use it, in this case cout is actually std::cout, but becuase
we are using the std namespace there is no need to "identify" cout with std.
int main()
This is the main function that is called when the program runs, this is absolutly important
you have this, the program WILL NOT work if you don't have this function.
the int before the main() is what must be returned when the function ends, in this case an
int which means an integer, there are other things im sure you have seen, void, uint32, and
others.
void basically means that the functions will return no value, uint32 means the function will
return a value of an uint32, exactly what a uint32 and other datatypes will be explained in
another tutorial.
{
This is an opening brace, it "opens" the function so code can be written in it and be
executed.
cout << "Hello World\n";
cout is a function that enables us to write to screen, there are other functions that can do
the same thing, but for the sake of this tutorial and simplicity I chose to use cout.
the << is an output operator, everything afer is is written to the cout function, so the
cout function can output the text to screen.
the quotations signify a string, what exactly a string is will be expalined in another
tutorial.
the \n is simply called an escape character, this certain one writes a new line, so if i
were to add more text it would be written on the line after Hello World!
return 0;
this piece of code tells the compiler to return a 0(zero) to the function.
}
this is a closing brace, this "closes" the function so any code after this will not be apart
of teh function!
;
this is required after most lines of code, this ends the line of code, certain things do not
need this, like an if, for, and others
If you have any questions please don't hesitate to ask!
There will be more tutorials!!!!
Created by: CoolManBob
using namespace std;
int main()
{
cout << "Hello World!\n";
return 0;
}
This is your basic Hello World Program.
This is usually the very first program people start out with when they begin doing
programming.
Im going to explain what each line does :)
#include <iostream>
# is a preproccessor symbol, you may have used it with #define, a preprocessor symbol tells
the compiler to do something before it starts compiling, in this case it tells the compiler
to find iostream.h and include it in this .cpp file.
When a compiler includes something, it means that the .cpp file can use functions that the
.h file declares.
using namespace std;
In programming there are things called Classes and namespaces, classes and namespaces are
similar to each other in that they both are a group of functions, but they are different.
Namespaces are a group of function identifiers, in this case std, this line tells the
compiler that the .cpp file is using the std namespace so every time a function has a std
identifier there is no need to use it, in this case cout is actually std::cout, but becuase
we are using the std namespace there is no need to "identify" cout with std.
int main()
This is the main function that is called when the program runs, this is absolutly important
you have this, the program WILL NOT work if you don't have this function.
the int before the main() is what must be returned when the function ends, in this case an
int which means an integer, there are other things im sure you have seen, void, uint32, and
others.
void basically means that the functions will return no value, uint32 means the function will
return a value of an uint32, exactly what a uint32 and other datatypes will be explained in
another tutorial.
{
This is an opening brace, it "opens" the function so code can be written in it and be
executed.
cout << "Hello World\n";
cout is a function that enables us to write to screen, there are other functions that can do
the same thing, but for the sake of this tutorial and simplicity I chose to use cout.
the << is an output operator, everything afer is is written to the cout function, so the
cout function can output the text to screen.
the quotations signify a string, what exactly a string is will be expalined in another
tutorial.
the \n is simply called an escape character, this certain one writes a new line, so if i
were to add more text it would be written on the line after Hello World!
return 0;
this piece of code tells the compiler to return a 0(zero) to the function.
}
this is a closing brace, this "closes" the function so any code after this will not be apart
of teh function!
;
this is required after most lines of code, this ends the line of code, certain things do not
need this, like an if, for, and others
If you have any questions please don't hesitate to ask!
There will be more tutorials!!!!
Created by: CoolManBob