← 返回刚才阅读的位置

知识卡片

普通读书笔记卡 · 10640.b.2 · 生成模型:未记录

分离标准输出和错误

理解等级:中级

用 println! 将匹配行写往 stdout,用 eprintln! 将诊断写往 stderr。调用者可通过 > output.txt 捕获正常数据。故意少传参数并重定向输出,可检查错误是否仍可见,结果文件是否保持为空。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《The Rust Programming Language(第2版)》第12章 I/O 项目:构建命令行程序(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c12.xhtml`,块 0293) - 结论依据:原文用两个流的不同用途解释重定向仍能保留错误诊断。 - 原始内容:At the moment, we’re writing all of our output to the terminal using the println! macro. In most terminals, there are two kinds of output: standard output (stdout) for general information and standard error (stderr) for error messages. This distinction enables users to choose to direct the successful output of a program to a file but still print error messages to the screen.