//Lori Walker //cs290, 11-7-95 //The follwoing program creates an input manipulator called getpass() that rings //the bell and then prompts for a password. #include #include //A simple input manipulator istream &getpass(istream &stream) { cout << '\a'; //'\a' makes the computer ring internal bell cout << "Enter password: "; return stream; } main() { char pw[80]; do { cin >> getpass >> pw; } while (strcmp(pw, "password")); cout << "Logon complete\n"; return 0; } //Custom manipulators can help to consolidate a sequence of several //separate I/O operations into one manipulator. It helps to simplify //your source code and prevent unwanted errors. //An input manipulator receives a reference to the stream for which it was //invoked. This stream must be returned by the manipulator. //It is crucial that your manipulators return stream. If not, your manipulator //cannot be used in a compound input or output expression. //The manipulator I have chosen is called &getpass (&reference) which is //supposed to ring the bell then prompt the user for a password. After which //it runs through a 'while' loop to do a string compare for the proper //password, and won't let you access until it is given correctly. Then outputs //to the screen "logon complete". A simple use of an istream.