All of standard input. Lines are read as text, so each line ends with a line feed, except a last line without one; carriage returns of CRLF line endings are kept as part of the line.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=:), | intent(out), | allocatable | :: | text |
the input |
subroutine read_stdin(text) !! All of standard input. Lines are read as text, so each line ends with a line feed, except a !! last line without one; carriage returns of CRLF line endings are kept as part of the line. use, intrinsic :: iso_fortran_env, only: input_unit use ffmt_strings, only: string_builder_t character(len=:), allocatable, intent(out) :: text !! the input type(string_builder_t) :: buf character(len=4096) :: chunk integer :: ios, n do read (input_unit, '(a)', advance='no', iostat=ios, size=n) chunk call buf%append(chunk(1:n)) if (is_iostat_eor(ios)) then call buf%append(achar(10)) else if (ios /= 0) then exit ! end of input end if end do text = buf%get() end subroutine read_stdin