Wednesday, April 03, 2002

Jello World







#include

#include

using namespace std;



int main()

{

string user_name;

cout << "What is your name: ";

cin >> user_name;

cout << '\n'

<< "Hello, "

<< user_name

<< "... and goodbye! \n ";



return 0;

}





This runs fine in VC++ using the iostream only, I guess by refering to the standard class only std instead of the Microsoft stdfx class ???



This sample comes from one of two books I'm using: Essential C++ by Stanley B. Lippman ISBN 0-201-48518-4 from Addison-Wesley C++ In-Depth Series. The other book is Bruce Eckel's Thinking in C++ which can be downloaded free from his site and bought in bookstores.



The covererage in this sample code is the "#include" command (or is it a keyword?) that brings in an object. The iostream itself is the standard C++ library of objects and is what gives understanding to the cin and cout keywords; notice the directions of the brackets used for each. Also the int TYPE declaration on the function MAIN() is declaring what will be the data type of the return value. In this case RETURN is zero, thus signaling success. Anything non-zero indicates failure. The RETURN 0 doesn't have to be specified as here if the keyword VOID is used instead of INT. That's what VOID means - nothing returned; whereas here just the fact that MAIN() has nothing in its () brackets - that itself declares that the function has no RETURN.



Also note the use of NAMESPACE to restrict these specific keywords used as coming from the STD library only.



String characters are shown proper format along with the "newline" (backslash N) declaration.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home