![]() |
Deciphering Hello World!
Hi,
I've been looking at the program Hello World and I've got some questions about a few of the lines contained in it. Firstly :
#include <iostream>I believe that this line calls part of C++ Standard Header called IOStream. What is IOStream and where can I get a listing and definition of all headers that can be called? :
int main()This is starting the main part of the program - i.e. where the code is wrote. :
std::cout << "Hello World!" << std::endl;:
return 0Thanks guys and I'd appreciate all comments. FM |
Look in your compiler's include directory; it's full of include files. Generally, when you consult your documentation regarding library function, it will tell you what headers you need to include.
Main does not have to return a zero. A zero is considered indicative of success. The '<<' operator of cout puts information into the stream. Endl adds a newline and causes the stream to be flushed. In my view, it couldn't get much simpler. I would suggest you get a good book on the language. A search of the forum will turn up a number of recommended titles. |
>I believe that this line calls part of C++ Standard Header called IOStream.
It doesn't "call" anything. #include is a preprocessor directive equivalent to cut and paste. The entire contents of the file designated by <iostream> are pasted into your file and replace the directive. >What is IOStream and where can I get a listing and definition of all headers that can be called? www.dinkumware.com gives a complete listing. >but is there a more simplistic way to do this Yes: :
#include <cstdio>>can someone please explain the operation of this line to me. For now, just trust that it works. The iostreams part of the standard library is extremely advanced and intense even for experienced C++ programmers. Using it is much easier than understanding it, which is a part of the design goal. :) >Is cout and endl contained within the iostream header file? Let's say yes and leave it at that. >Return 0 means return nothing? It means return success. Any non-zero value signifies failure. >I assume thaty the main will always return 0 as it is the top of the hierarchy, >but that child procedures called from it and subsequently can return different >types of parameters and values? As written, yes. However, you can also call a function called exit which will immediately return potentially another value. |
:
#include <iostream>good luck! |
Quote:
|
Quote:
|
From the standard: "Finally, control is returned to the host environment. If the value of status is zero or EXIT_SUCCESS, an implementation-defined form of the
status successful termination is returned." This seems to imply that EXIT_SUCCESS might not be 0, but that a zero will indicate a successful termination, even should the implementation care to remap it to a non-zero value. |
Quote:
|
I understand that. It has some characteristics of a NULL pointer, wot?
|
>Apparently it was not 0 on some historic VAX system. I said I was knit-picking ;-)
0 is 0, but this concept causes untold confusion. Usually the confusion is with null pointers, where 0 is a null pointer, but a null pointer isn't necessarily 0. ;) |
| All times are GMT -5. The time now is 1:03 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC