[ Character I/O | Reference Manual | Alphabetic Index ]

# put(+Stream, +Code)

The character represented by the integer code Code is put onto the buffered output stream Stream.

Stream
  Stream handle or alias (atom)
Code
  Integer.

## Description

Writes the character (or byte, in case of binary stream) represented by the integer Code onto the output stream Stream. The acceptable value range depends on the stream's character encoding, or is 0 to 255 for binary streams.

Note that the output from put/2 is usually buffered, and is only output to the stream when the output is flushed (e.g. using flush/1).

Character codes for the non-printable characters (i.e. control characters) are also acceptable.

### Modes and Determinism

- put(+, +) is det

### Exceptions

(4) instantiation fault
  Stream is not instantiated.
(4) instantiation fault
  Code is not instantiated.
(5) type error
  Stream is neither a stream handle nor an atom.
(5) type error
  Code is instantiated, but not to an integer.
(192) illegal stream mode
  Stream is not an output stream.
(193) illegal stream specification
  Stream is an illegal stream specification.

## Examples

    Success:
          ?- put(output, 0'a).
          a
          yes.

          ?- sh('cat file1').
          a
          yes.
          ?- open(file1,read,s1),
             open(file2,write,s2),repeat,
             ( at_eof(s1) ->
                  !,
                  flush(s2),
                  close(s1),close(s2)
             ;
                  get(s1,Char),
                  put(s2,Char),
                  fail
             ).
          Char = _g72
          yes.
          ?- sh('cat file2').
          a
          yes.

    Error:
          put(output,A).             (Error 4).
          put(Stream,98).            (Error 4).
          put(output, '98').         (Error 5).
          put(output, 98.0).         (Error 5).
          put("string" A).           (Error 5).
          put(11,97).                (Error 192). % stream not open
          put(atom,97).              (Error 193).

## See Also

get / 1, get / 2, put / 1, nl / 1