코딩Coding/Rust연습

러스트연습숫자가 0부터 계속 올라감 계속 그 자리에서 출력

내인생PLUS 2022. 8. 14. 00:09
728x90

 

 

use std::io::Write;
use std::thread;
use std::time;

fn main() {
    let mut bun: u64 = 0;

    loop {
        print!("\r{}", bun);
        std::io::stdout().flush().unwrap();

        bun += 1;

        thread::sleep(time::Duration::from_millis(100));
    }
}

 

숫자가 0부터 계속 올라감 계속 그 자리에서 출력

 

cargo run
   Compiling char v0.1.0 (/Users/globalyoung/Documents/test/rust/char)
    Finished dev [unoptimized + debuginfo] target(s) in 0.15s
     Running `target/debug/char`
174^Z
[4]  + 6081 suspended  cargo run

 

 

 

 

 

https://stackoverflow.com/questions/68294536/counter-only-displays-at-10hz-if-its-printed-with-eprint-to-stderr-vs-print

 

Counter only displays at 10Hz if it's printed with eprint! to stderr vs. print! to stdout

I wrote a program to simply increment a counter and display it in the terminal window: use std::thread; use std::time; fn main() { let mut bun: u64 = 0; loop { print!("\r{}&q...

stackoverflow.com

 

 

 

 

 

 

 


 

반응형