Next: , Previous: String Library, Up: Function Descriptions


7.1.4 Input/Output

The first group of functions operate on stdin and stdout for interactiion with the user. The scan input functions with throw a run-time exception upon conversion failure.

— Function: echo args...
— Function: cout args...
— Function: print args...
Prints all arguments sequentially to stdout. The print variant includes a terminating newline, while the others do not.
— Function: printerr args...
— Function: cerr args...

Prints all arguments sequentially to stderr. The printerr variant includes a terminating newline, while the others do not.

— Function: zscan
— Function: dzscan

Read an integer from stdin. Use with caution, because events in the simulator are relatively asynchronous. The `d' in the dzscan command alias is for decimal, base-10. See also zscan_prompt.

— Function: zscan_prompt str
— Function: dzscan_prompt str

Same as zscan, but takes a prompt string str as an argument and prints it to prompt the user.

— Function: bzscan

Reads an integer, expected in binary, containing only 0's and 1's. Input should exclude any “0b” prefix.

— Function: bzscan_prompt str

Prompts use to enter an integer in binary.

— Function: xzscan

Reads an integer, expected in hexadecimal. Input may include an optional “0x” prefix.

— Function: xzscan_prompt str

Prompts use to enter an integer in hexadecimal.

— Function: bscan

Read a boolean (0 or 1) from stdin. Use with caution, because events in the simulator are relatively asynchronous. See also bscan_prompt.

— Function: bscan_prompt str

Same as bscan, but takes a prompt string str as an argument and prints it to prompt the user.

— Function: sscan

Reads a newline-terminated string from stdin.

— Function: sscan_prompt str

Same as sscan, but takes a prompt string str as an argument and prints it to prompt the user.

TODO: rscan is not yet available, but is trivial to add.

I/O can also operate on file streams.

— Function: fopen file

Open file file for writing, overwrite previous contents. Subsequent calls to fprint will still continue to append to the file. If the file stream is already open, do nothing. Return true if the stream is opened successfully (or was already open).

— Function: fappend file

Like fopen, except file is first opened in append mode, to not overwrite existing file. Call this before fprint to append to file.

— Function: fprint file args...

Print args to file file by appending. Throw run-time exception if opening file fails. File streams are automatically closed and flushed upon library closing.

— Function: fclose file

Close and flush file input and output stream(s) file.

— Function: fflush file

Flush output file stream file.

— Function: fzscan file
— Function: fdzscan file

Read the next integer from input file file. Expects integer in decimal. Automatically opens new input file stream when referenced first time.

— Function: fbzscan file

Same as fzscan, but expects integer in binary.

— Function: fxzscan file

Same as fzscan, but expects integer in binary.

— Function: fbscan file

Read the next boolean from input file file. Automatically opens new input file stream when referenced first time.

— Function: fsscan file

Read the next boolean from input file file. Automatically opens new input file stream when referenced first time.

The following variants automatically restart a file stream once it reaches the end.

— Function: fzscan_loop file
— Function: fdzscan_loop file

Read the next integer from input file file. Re-opens file to beginning after EOF is reached.

— Function: fbzscan_loop file

Like fzscan_loop, but expects integer in binary.

— Function: fxzscan_loop file

Like fzscan_loop, but expects integer in hexadecimal.

— Function: fbscan_loop file

Read the next boolean from input file file. Re-opens file to beginning after EOF is reached.

— Function: fsscan_loop file

Read the next boolean from input file file. Re-opens file to beginning after EOF is reached.