Reading from stdin()


#1

Hi, everyone.
What’s the latest and least verbose way to

  • Read from stdin until ‘\n’ (or line break) is detected and storing into a string? For example:

string input = readln();

  • Read until EOF is reached and storing it into a string? For example:
string result;
foreach(string line; lines(stdin))
    result ~= line;

#2

To read a line, https://doc.rust-lang.org/std/io/struct.Stdin.html#method.read_line.

Till EOF, https://doc.rust-lang.org/std/io/trait.Read.html#method.read_to_string (Stdin implements Read, so this method is available if Read is imported).