Always talking about read & write i noticed another interesting thing:

use std::io::buffered::BufferedReader;
use std::io::stdin;

fn main()
{
    print!("Insert your name: ");
    let mut stdin = BufferedReader::new(stdin());
    let s1 = stdin.read_line().unwrap_or(~"nothing");
    print!("Welcome, {}", s1);
}

when i run this simple code the output "Insert your name" doesn't appear on
the screen... only after typing and entering a string the whole output
jumps out... am i missing some "flush" (ala Fantom) or similar? I am using
Rust 0.9 on W7.


On Sun, Feb 9, 2014 at 2:40 AM, Patrick Walton <[email protected]> wrote:

> On 2/8/14 3:35 PM, Alex Crichton wrote:
>
>> We do indeed want to make common tasks like this fairly lightweight,
>> but we also strive to require that the program handle possible error
>> cases. Currently, the code you have shows well what one would expect
>> when reading a line of input. On today's master, you might be able to
>> shorten it slightly to:
>>
>>      use std::io::{stdin, BufferedReader};
>>
>>      fn main() {
>>          let mut stdin = BufferedReader::new(stdin());
>>          for line in stdin.lines() {
>>              println!("{}", line);
>>          }
>>      }
>>
>> I'm curious thought what you think is the heavy/verbose aspects of
>> this? I like common patterns having shortcuts here and there!
>>
>
> Is there any way we can get rid of the need to create a buffered reader?
> It feels too enterprisey.
>
> Patrick
>
>
> _______________________________________________
> Rust-dev mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/rust-dev
>
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to