@ acorn: Double check his sentence structure, I don't think English is his primary language and that's what most C++ books are written in. He might be looking for another way to state the explainations so that he can translate and cross reference, and that is a
heck of a lot more conviction then I've ever had.
@ OP: Sure but first lets make it easy to read:
1 2 3 4 5 6 7 8 9 10
|
// my first program in C++
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello World!";
return 0;
}
| |
Line 1: I'm sure you know that this is what is called a comment and is not part of the program
Line 3:
#include <iostream>
Tells the compiler to open a file called "iostream" and act like everything written in that file is also written in your file. This saves us from having to rewrite the same code over and over.
Line 4: This tells the compiler to use a "namespace" called "std", the best way I can explain this is that you are telling the compiler that you are writting in short hand using the method outlined in std.
Line 6: This is the entry point for the program, your compiler starts working its magic from this point on. The
int
also tells the Operating System to expect an integer returned when it is done processing, this is very important latter on.
Line 7: Start of your function.
Line 8: cout is some of the shorthand I mentioned earlier, in this case it is short for
std::cout
and is telling the compiler to send the following data, in this case the collection of characters "Hello World!", to the standard output stream. More here:
http://www.cplusplus.com/reference/iostream/cout/
Line 9: This is the integer returned to the Operating System. EDIT: Note that Zero usuallly means that the program executed and finished without any trouble.
Line 10: End of function.