The functions in this section operate only on stdout. For generic file I/O please see the File class.
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.
f_printf(format_string, arguments...
)
f_printf("%5s\n", "long string"); # will print "long \n", respecting the 5-character field width
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.
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.
f_sprintf(format_string, arguments...
)
$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.
Flushes output to the console output with print(), printf(), etc.
flush()
flush();
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.
Outputs a string to standard output with no formatting. See printf() for a function that allows for formatted output.
print(string
)
print("hello\n"); # do not use formatting with this function
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.
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.
printf(format_string, arguments...
)
printf("%5s\n", "a long string"); # will output "a long string", exceeding the field width
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.
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.
sprintf(format_string, arguments...
)
$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.
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.
vprintf(format_string, arg_list
)
vprintf("%5s %3d\n", ("a long string", 5000)); # outputs "a long string 5000", exceeding field width of 5
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.
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.
vsprintf(format_string, arg_list
)
$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.