코딩Coding/Rust연습
Rust연습❤️물어보고 출력 무한 loop
내인생PLUS
2022. 8. 14. 00:02
728x90
use std::io::{self, Write};
fn main() {
let mut stdin = io::stdin();
let input = &mut String::new();
loop {
input.clear();
print!("Your age: ");
io::stdout().flush();
stdin.read_line(input);
print!("{}", input);
}
}
warning: `char` (bin "char") generated 3 warnings
Finished dev [unoptimized + debuginfo] target(s) in 0.16s
Running `target/debug/char`
Your age: 324
324
Your age: 11
11
Your age: q
q
Your age: 20
20
Your age: 2-
2-
Your age: 1
1
Your age: 2
2
Your age: 3
3
Your age: Your age: ^C
https://stackoverflow.com/questions/39154107/how-to-avoid-going-to-new-line-with-stdin-in-rust
반응형