

You should be looking at an empty _tmain function and an include to some currently unnecessary header files. Let's explain these things.
A header file is just a file that you can include into your application, any functions that you place into the header file will be available in any application which includes it. That is accomplished through the #include compiler directive.
Here is the code:
#include
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
cout<<"Hello World";
return 0;
}
pretty easy huh?
The first thing you see after the #include is 'using namespace std;' This tells the compiler where to look for functions. For now just think of it like that. Very important, but for now just remember to put it there and all will be fine.
Let's look at how a function works.
return_type function_name(arg_type arg_name,...)
_tmain is the name of the function that serves as the entry point to your program. It is run automatically when you run your application. The int argc is an integer (whole number) that tells you how many arguments were passed to your program and _TCHAR* argv[] is an array of character pointers that stores all of the arguments passed into your program. Wow, an array... ok so imagine a chest of drawers. Give each drawer a number. This is pretty much how an array works. Only whereas you can put whatever you want in a drawer, an array is limited to whatever type you make it, in this case a _TCHAR*. Pointers are a bit more complicated. A pointer doesn't actually store the value, it stores the location in memory at which you can find a value. By having an array of pointers you can efficiently store strings (words) of different lengths in the same array. Don't worry if this didn't all make sense. We will be doing more with this stuff later.
now you see 'cout<<"Hello world";' cout is a type of function, it lets you put text to the screen, it's counterpart cin lets you retrieve keyboard input. There are other alternatives which I think I will go into which have more power but are a bit more complex, so for now, we'll be using these for text stuff.
Now, for the 'return 0;' this just returns 0 to whatever called your program, 0 being the default all is well number. You can return whatever number you want. Most functions can return whatever type you want, but this one can only return a number. Well, that's it for now. I will be coming up with some interesting projects to tackle together in a bit. Hope this helps, and be sure to post comments and questions!
No comments:
Post a Comment