read Stdin() - > string- Модуль
- std.
io → - Получатель
- Неприменимо
- Минимальное число аргументов
- 0
- Максимальное число аргументов
- 0
Declaration and parameters
СсылкаДоступность
Включено по умолчанию · Не определено
Import std.io in language mode 5.21.
The current compiler selects std/io.tpz for this language mode. Availability in other released editions and inclusion in each installed distribution are Pending.
Получатель
Ограничения параметров
read reads the remaining standard input bytes through EOF. UTF-8 validity and text preservation follow UTF-8 decoding. It does not append or remove a newline.
No remaining bytes produces an empty string. A later call reads from the stream position left by the earlier call and therefore returns an empty string at EOF. A terminal follows the same EOF rule as redirected input.
The call may wait for input or EOF. Reading consumes input even when the result is later discarded. A host read failure or invalid UTF-8 produces a structured runtime fault at the readStdin call because the function returns a string rather than a Result.
The Topaz 6.0 host input fault is TPZ4008. Its primary location is the readStdin call.
Связанное правило · Read standard input through its end →Результат
The declared result type is string.
Эффекты
Ошибки
Result and effects
СсылкаConsume the remaining standard input through EOF as strict UTF-8 text. Preserve whitespace and return empty text when no bytes remain.
Related entries
СсылкаRead standard input through its end
СсылкаRead standard input through its end
read reads the remaining standard input bytes through EOF. UTF-8 validity and text preservation follow UTF-8 decoding. It does not append or remove a newline.
No remaining bytes produces an empty string. A later call reads from the stream position left by the earlier call and therefore returns an empty string at EOF. A terminal follows the same EOF rule as redirected input.
The call may wait for input or EOF. Reading consumes input even when the result is later discarded. A host read failure or invalid UTF-8 produces a structured runtime fault at the readStdin call because the function returns a string rather than a Result.
The Topaz 6.0 host input fault is TPZ4008. Its primary location is the readStdin call.
Причина
Standard input is a stream shared with the host. Consuming it once gives EOF one meaning and lets terminal and redirected input obey the same rule. Strict UTF-8 prevents malformed bytes from silently becoming different text.
Preserve redirected text and its line endings
Ссылкаimport std.iolet text = io.readStdin()io.writeLine(text)
alpha
한글
Ожидаемый результат
Ожидаемый результат
Выполнение завершается. Код завершения 0.
alpha한글
Return empty text at an empty input stream
Ссылкаimport std.iolet text = io.readStdin()let empty = text == ""io.writeLine("{empty}")
true
Ожидаемый результат
Ожидаемый результат
Выполнение завершается. Код завершения 0.
true
Observe EOF after standard input has been consumed
Ссылкаimport std.iolet first = io.readStdin()let second = io.readStdin()let atEnd = second == ""io.writeLine(first)io.writeLine("{atEnd}")
alpha
true
Ожидаемый результат
Ожидаемый результат
Выполнение завершается. Код завершения 0.
alphatrue