As stdout is line-buffered, stdout is not implicitly flushed until a new-line is encountered. This means that the print! macro does not act like a println! without the newline as the documentation suggests. To be equivalent, the user must explicitly flush stdout like the following:
use std::io::prelude::*;
use std::io;
fn main() {
print!("Type something: ");
io::stdout().flush().ok().expect("Could not flush stdout");
// Read stdin, etc.
}
For easy use of the print macros, the user should not need to know about how I/O flushing works. As such, print! should explicitly flush stdout itself.
As stdout is line-buffered, stdout is not implicitly flushed until a new-line is encountered. This means that the
print!macro does not act like aprintln!without the newline as the documentation suggests. To be equivalent, the user must explicitly flush stdout like the following:For easy use of the print macros, the user should not need to know about how I/O flushing works. As such,
print!should explicitly flush stdout itself.