3.2. Output Functions

The functions in this section operate only on stdout. For generic file I/O please see the File class.

3.2.1. f_printf()

Synopsis

Outputs a formatted string to standard output, respecting field widths in the formatting string. See String Formatting for information on the formatting string, and see printf() for a similar function that does not enforce field widths.

Usage
f_printf(format_string, arguments...)
Example
f_printf("%5s\n", "long string"); # will print "long \n", respecting the 5-character field width
Restrictions

Not available with PO_NO_TERMINAL_IO

Table 3.30. Arguments and Return Values for f_printf()

Arguments

Return Type

Description

String, [...]

String

Returns the string output (see String Formatting for information on the format string)


This function does not throw any exceptions.

3.2.2. f_sprintf()

Synopsis

Returns a formatted string without doing any output, respecting field widths. See String Formatting for information on the formatting string, and see sprintf() for a similar function that does not enforce field widths.

Usage
f_sprintf(format_string, arguments...)
Example
$str = f_sprintf("%5s", "a long string"); # will return "a lon"

Table 3.31. Arguments and Return Values for f_sprintf()

Argument Type

Return Type

Description

String, [args...]

String

Returns a formatted string without doing any output, enforcing any field widths. See String Formatting for information on the format string.


This function does not throw any exceptions.

3.2.3. flush()

Synopsis

Flushes output to the console output with print(), printf(), etc.

Usage
flush()
Example
flush();
Restrictions

Not available with PO_NO_TERMINAL_IO

Table 3.32. Arguments and Return Values for flush()

Arguments

Return Type

Description

n/a

n/a

Thie function takes no arguments.


This function does not throw any exceptions.

3.2.4. print()

Synopsis

Outputs a string to standard output with no formatting. See printf() for a function that allows for formatted output.

Usage
print(string)
Example
print("hello\n"); # do not use formatting with this function
Restrictions

Not available with PO_NO_TERMINAL_IO

Table 3.33. Arguments and Return Values for print()

Argument Type

Return Type

Description

String

n/a

Outputs the string to stdout with no formatting.


This function does not throw any exceptions.

3.2.5. printf()

Synopsis

Outputs the string passed to standard output, using the first argument as a formatting string. See f_printf() for a similar function that enforces field widths, and print for an simple output function that does not accept a formatting string. See String Formatting for information on the formatting string.

Usage
printf(format_string, arguments...)
Example
printf("%5s\n", "a long string"); # will output "a long string", exceeding the field width
Restrictions

Not available with PO_NO_TERMINAL_IO

Table 3.34. Arguments and Return Values for printf()

Arguments

Return Type

Description

String, [...]

String

See String Formatting for information on the format string. This is the "normal" (non-field) printf() version, so any field widths are considered as soft limits, and arguments are allowed to exceed their field widths. Only when an argument is less than the field width will it be padded to the field width specified. Returns the string output.


This function does not throw any exceptions.

3.2.6. sprintf()

Synopsis

Returns a formatted string without enforcing hard field limits. See f_sprintf() for a similar function that enforces field widths, and see String Formatting for information on the formatting string.

Usage
sprintf(format_string, arguments...)
Example
$str = sprintf("%5s", "a long string"); # returns "a long string", exceeding the field width

Table 3.35. Arguments and Return Values for sprintf()

Argument Type

Return Type

Description

String, [args...]

String

See String Formatting for information on the format string. Field widths are considered soft limits (arguments are allowed to exceed their field widths). Only when an argument is less than the field width will it be padded to the field width specified.


This function does not throw any exceptions.

3.2.7. vprintf()

Synopsis

Outputs a formatted string based on a variable number of arguments given in a list after the format string and returns the string printed. See String Formatting for information on the formatting string.

Usage
vprintf(format_string, arg_list)
Example
vprintf("%5s %3d\n", ("a long string", 5000)); # outputs "a long string 5000", exceeding field width of 5
Restrictions

Not available with PO_NO_TERMINAL_IO

Table 3.36. Arguments and Return Values for vprintf()

Argument Type

Return Type

Description

String, [List]

String

See String Formatting for information on the format string. Arguments to the formatting string are supplied in the optional second argument as a list. Field widths are considered as soft limits; arguments are allowed to exceed their field widths. Only when an argument is less than the field width will it be padded to the field width specified. Returns the string output.


This function does not throw any exceptions.

3.2.8. vsprintf()

Synopsis

Formats a string based on two arguments: a format string and a list. Does not enforce hard field widths. Returns this formatted string. See String Formatting for information on the formatting string.

Usage
vsprintf(format_string, arg_list)
Example
$str = vsprintf("%5s %3d\n", ("a long string", 5000)); # returns "a long string 5000", exceeding field width of 5

Table 3.37. Arguments and Return Values for vsprintf()

Argument Type

Return Type

Description

String, [List]

String

See String Formatting for information on the format string. Arguments to the formatting string are supplied in the optional second argument as a list. Field widths are considered soft limits (arguments are allowed to exceed their field widths). Only when an argument is less than the field width will it be padded to the field width specified. Returns the formatted string.


This function does not throw any exceptions.