暂停生锈

2022-11-24

以下示例是关于Rust中包含暂停生锈用法的示例代码,想了解暂停生锈的具体用法?暂停生锈怎么用?暂停生锈使用的例子?那么可以参考以下相关源代码片段来学习它的具体使用方法。

[英]:pause rust源码类型:Rust
use std::io;
use std::io::prelude::*;

fn pause() {
    let mut stdin = io::stdin();
    let mut stdout = io::stdout();

    // We want the cursor to stay at the end of the line, so we print without a newline and flush manually.
    write!(stdout, "Press any key to continue...").unwrap();
    stdout.flush().unwrap();

    // Read a single byte and discard
    let _ = stdin.read(&mut [0u8]).unwrap();
}

fn main() {
    // Do some stuff
    pause();
}

本文地址:https://www.itbaoku.cn/snippets/806014.html