/* ** $Id: hello.cc 824 2008-03-09 19:23:52Z phf $ */ // The iostream include allows access to the standard // input/output/error streams, similar to stdio.h for // regular C programming. #include int main() { // The "std" namespace refers to elements of the // standard library. If we'd put // // using namespace std; // // or (slightly better) // // using std::cout; // using std::endl; // // before main(), we could write // // cout << "Hello World!" << endl; // // instead of what we write here. However, we did // discuss why this "using" stuff is a bad idea. std::cout << "Hello World!" << std::endl; // The "<<" operator refers to an overloaded method; // overloaded versions exist for strings, ints, and // all kinds of other "standard" types which can all // be printed this way. Writing several "<<" next to // each other works because "<<" returns the stream // that it modifies. In other words, the line above // evaluates as // // (std::cout << "Hello World!") << std::endl; // (std::cout << std::endl); // (std::cout); // // and finally the value is ignored, but not before // the two parts were written to the standard output. // We can see this more clearly as follows: First, // we could have written the same output using two // instructions: std::cout << "Hello World!"; std::cout << std::endl; // Second, if we evaluate std::cout by itself, nothing // whatsoever happens on the output. std::cout; // we'll get a warning about "no effect" here // If we don't put a return here, the compiler will // add a "return 0;" by default indicating that the // program worked "okay" to the shell. return 0; }