← 返回刚才阅读的位置

知识卡片

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

read_line追加到缓冲区

理解等级:中级

标准输入读行时借用调用者的 &mut String,写入内容追加到缓冲区末尾。猜数字每轮创建新缓冲区,因此每轮只解析当前行。若复用缓冲区,应明确清空时机,同时分开处理返回的字节数或 I/O 错误。

相关卡片 [[从输入边界区分错误]]

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • 猜数字游戏 Receiving User Input · 查看原书依据

      Next, the line .read_line(&mut guess) calls the read_line method on the standard input handle to get input from the user. We’re also passing &mut guess as the argument to read_line to tell it what string to store the user input in.

    参考来源

    - 位置:《The Rust Programming Language(第2版)》第02章 猜数字游戏(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c02.xhtml`,块 0050) - 结论依据:原文明说 read_line 追加且需要能修改传入的 String。 - 原始内容:Next, the line .read_line(&mut guess) calls the read_line method on the standard input handle to get input from the user. We’re also passing &mut guess as the argument to read_line to tell it what string to store the user input in.