Перейти к содержимому
Топаз6.0 · До релиза
Загрузка →

Поиск в документации

Спецификация 6.0

Выберите результат стрелками и нажмите Enter, чтобы открыть его.

Введите имя API, номер диагностики, правило или тему проекта.

    Библиотека

    std.io.readStdin

    Reads from standard input.

    readStdin() -> 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.

    Получатель

    Ограничения параметров

    readStdin 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.

    Результат

    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

    Ссылка

    std.io →

    Read standard input through its end

    Ссылка
    Правилоtopaz.stdlib.contract.stdin-consumption.rule

    Read standard input through its end

    readStdin 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

    Ссылка
    main.tpzPreserve redirected text and its line endingsОткрыть песочницу →
    1. import std.io
    2. let text = io.readStdin()
    3. io.writeLine(text)
    Ожидаемый выводКод завершения 0
      alpha
    한글
    
    
    $ topaz run main.tpz · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. alpha
    2. 한글

    Return empty text at an empty input stream

    Ссылка
    main.tpzReturn empty text at an empty input streamОткрыть песочницу →
    1. import std.io
    2. let text = io.readStdin()
    3. let empty = text == ""
    4. io.writeLine("{empty}")
    Ожидаемый выводКод завершения 0
    true
    
    $ topaz run main.tpz · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. true

    Observe EOF after standard input has been consumed

    Ссылка
    main.tpzObserve EOF after standard input has been consumedОткрыть песочницу →
    1. import std.io
    2. let first = io.readStdin()
    3. let second = io.readStdin()
    4. let atEnd = second == ""
    5. io.writeLine(first)
    6. io.writeLine("{atEnd}")
    Ожидаемый выводКод завершения 0
    alpha
    true
    
    $ topaz run main.tpz · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. alpha
    2. true

    Меню

    Загрузка →