코딩Coding/Rust연습

Rust연습_H가 같은줄에 출력에서 앞으로 계속 쌓임.

내인생PLUS 2022. 8. 14. 00:06
728x90
use std::io::Write;
use std::time::Duration;
fn main() {
    let ch = 'H' as u8;
    for _ in 0..20 {
        let buff = vec![ch];
        std::io::stdout().write(&buff).unwrap();
        std::io::stdout().flush().unwrap();
        std::thread::sleep(Duration::from_millis(1000));
    }
}

 

 

결과

cargo run
   Compiling char v0.1.0 (/Users/globalyoung/Documents/test/rust/char)
    Finished dev [unoptimized + debuginfo] target(s) in 0.17s
     Running `target/debug/char`
HHHHHHHHHHHH^Z
[3]  + 5989 suspended  cargo run

 

 

 

https://stackoverflow.com/questions/63590925/how-to-do-non-buffered-writes-to-stdout

 

How to do non-buffered writes to stdout?

I need 20 'H' characters to appear at 1 second intervals. This program displays nothing till the end use std::io::Write; use std::time::Duration; fn main() { let ch = 'H' as u8; for _ in 0....

stackoverflow.com

 

 

 

 

 

 

 


 

반응형