I'm reading a string like this:
print!("Input string: ");
let string: String = String::new();
std::io::stdin().read_line(&mut string);
When I launch the program I see:
(write a string here)
Input string:
But I need:
Input string: (write a string here)
How to implement this?
Add a call to stdout().flush()
to force the buffer to output before read_line
is called:
fn main() {
print!("Input string: ");
std::io::stdout().flush();
let mut string: String = String::new();
std::io::stdin().read_line(&mut string);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With