/* File: hello2-eof.cpp greets the user by name uses an eof-controlled while loop */ #include //for cout, cin, endl #include //for type string using namespace std; //make std names available w/o std:: prefix int main(){ string fname; //first name //prompt and read user's first name cout << "enter first name (c-d to exit): "; cin >> fname; while(cin){ //print greetings and flush the i/o buffer cout << "Hello, " << fname << " and fare thee well!" << endl; //prompt and read user's first name cout << "enter first name (c-d to exit): "; cin >> fname; } cout << endl << "Exiting.." << endl; return 0; } /* NOTES: The return statement may be omitted in main(). If it's omitted, a "return 0;" statement is inserted automatically by the compiler. main() is special in this sense, as this will not be done for any other function. EXERCISES: Change the name of main() to Main() and recompile. What happens? Comment out the header and recompile. What happens? Comment out the header and recompile. What happens? Extend the program to greet the user by first and last name. */