use std::io;
fn main() {
println!("Welcome!");
let mut input = String::new();
print!("Please type something:"); // this line is not printed UNTIL the Enter key is pressed
io::stdin()
.read_line(&mut input)
.expect("Failed to read input!");
println!("Bye!");
}
发生以下情况:
Welcome! 打印
Please type something: 未打印
如果你输入一些文本并按 Enter 键,你会看到你的文本后面跟着 Please type something:Bye!
如何将消息打印到标准输出并将输入打印在同一行上?
例如:
Please enter your name:
(user types Chuck Norris)
Please enter your name: Chuck Norris
print! 宏直到按下 Enter 键才执行
下载声明:
本站所有软件和资料均为软件作者提供或网友推荐发布而来,仅供学习和研究使用,不得用于任何商业用途。如本站不慎侵犯你的版权请联系我,我将及时处理,并撤下相关内容!