Java OpenResty Spring Spring Boot MySQL Redis MongoDB PostgreSQL Linux Android Nginx 面试 小程序 Arthas JVM AQS juc Kubernetes Docker 诊断工具


Rust 标准库 API 输入 stdin 输出 stdout 错误输出 stderr

Rust 大约 608 字

stdin

使用read_line获取输入字符串。

use std::io;

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input).expect("Failed to read line");
    println!("{}", input);
}

stdout

use std::io;
use std::io::Write;

fn main() {
    let mut output = String::new();
    output.push_str("Hello World From Rust");

    io::stdout().write(&output.as_bytes()).expect("Failed to write out");
}

stderr

use std::io;
use std::io::Write;

fn main() {
    let mut err = String::new();
    err.push_str("Error From Rust\n");

    io::stderr().write(&err.as_bytes()).expect("Failed to write err");
}
阅读 537 · 发布于 2023-04-13

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb

扫描下方二维码关注公众号和小程序↓↓↓

扫描二维码关注我
昵称:
随便看看 换一批