simpio.h
Functions | |
Reads a complete line from user input and scans it as an integer. | |
Reads a line of text from user input and returns that line as a string. | |
Reads a complete line from user input and scans it as a floating-point number. | |
Reads a complete line from user input and treats it as a yes-or-no answer to a question, returning a boolean value of true for yes and false for no. |
|
Prompts user to enter the name of a file and returns it. |
int getInteger(string prompt = "", string reprompt = "");
prompt
string is printed before reading the value.
If the scan succeeds, the integer value is returned. If
the argument is not a legal integer or if extraneous characters
(other than whitespace) appear in the string, the user is given
a chance to reenter the value. The optional reprompt
message is
displayed before asking the user to reenter an illegal value.
If no reprompt argument is given, the message defaults to "Illegal integer format. Try again.".
Usage:
int age = getInteger("Please enter your age:");
double getReal(string prompt = "", string reprompt = "");
prompt
string is printed before reading the value.
If the scan succeeds, the floating-point
value is returned. If the input is not a legal number or if
extraneous characters (other than whitespace) appear in the string,
the user is given a chance to reenter the value. The optional reprompt
message is
displayed before asking the user to reenter an illegal value.
If no reprompt argument is given, the message defaults to "Illegal numeric format. Try again.".
Usage:
double price = getReal("Enter the item price:");
string getLine(string prompt = "");
prompt
string is printed before reading the value.
Usage:
string line = getLine("What is your name?");
bool getYesOrNo(string prompt = "", string reprompt = "");
true
if the line typed begins with a 'y' or 'Y', and returns false
if it begins with a 'n' or 'N'. If supplied, the optional prompt
string is printed before reading the value.
If the user's input is not a valid Y or N response, they are asked to reenter.
The optional reprompt
message is
displayed before asking the user to reenter an illegal value.
If no reprompt argument is given, the message defaults to "Please type a word that starts with 'Y' or 'N'.".
Usage:
if (getYesOrNo("Do you want to play another round?")) { ...
string promptUserForFilename(string prompt = "", string reprompt = "");
The optional prompt
argument provides an input prompt
for the user.
The also optional reprompt
argument provides an output message displayed each time if the user types a file that is not found.
If no value is passed it defaults to, "Unable to open that file. Try again.".
Usage:
string filename = promptUserForFilename("Enter a filename: ");