我读过有关在How to read an integer input from the user in Rust 1.0?中读取整数输入的文章,但我注意到所有的解决方案都首先接受字符串作为输入,然后将其转换为整数。我想知道是否有一种方法可以直接读取整数。
This page提到了scan!()宏,但由于某种原因,当我使用rustc main.rc编译以下程序时,它似乎不能运行。
extern crate text_io;
fn main() {
let mut a: u8;
let mut b: u8;
scan!("{},{}", a, b);
print!("{} {}", a, b);
}这会产生以下错误:
error: macro undefined: 'scan!'
scan!("{},{}",a,b);发布于 2016-07-15 21:00:27
您必须显式地说明您希望从此机箱中导入宏:
#[macro_use] extern crate text_io;这篇文章写在自述文件的最顶端,你一定是错过了。
要使用crates.io中的板条箱,您需要将它们添加到Cargo.toml中,例如,通过将以下行添加到该文件:
[dependencies]
text_io = "0.1"https://stackoverflow.com/questions/38396104
复制相似问题