In

Source: lib/In.cs

This page is generated from the source by scripts/gen-reference.py.

Buffered stdin reader for zero mode, the counterpart of Out.

Span<char> buffer = stackalloc char[80];
Out.Write($"Q{i}: {a} + {b} = ");          // In flushes Out before reading
int length = In.ReadLine(buffer);
if (length < 0) ...                         // end of input
if (length > buffer.Length) ...             // too long; the rest was skipped
ReadOnlySpan<char> answer = buffer.Slice(0, length);

The line goes into the caller's buffer, so reading allocates nothing. To keep one past the next read, copy it: Str.ToArenaString(arena, answer). Input is decoded as UTF-8 (invalid bytes become U+FFFD), and the line ending, "\n" or "\r\n", is left out.

Members

ReadLine

public static int ReadLine(Span<char> buffer)

Reads one line into buffer and returns its length, or -1 at the end of input. A line longer than the buffer returns its full length: the buffer holds its first buffer.Length chars and the rest is skipped.