“宏未定义";当使用scan读取u8时!() [英] "macro undefined" when reading u8 using scan!()

查看:96
本文介绍了“宏未定义";当使用scan读取u8时!()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读到有关读取

I read about reading integer input in How to read an integer input from the user in Rust 1.0?, but I noticed that all the solutions first take a string as input and then convert it to integer. I wonder if there's a way to read an integer directly.

此页面提到了scan!()宏,但是由于某些原因,它没有当我使用rustc main.rc编译以下程序时,似乎没有运行.

This page mentions scan!() macro but for some reason it doesn't seem to run when I compile the following program using 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);

推荐答案

您必须明确地说您要从此板条箱中导入宏:

You have to explicitly say that you want to import macros from this crate:

#[macro_use] extern crate text_io;

本文写在自述文件的最顶部,您一定错过了.

This is written at the very top of the readme, you must have missed it.

要使用crates.io中的包装箱,您需要将其添加到Cargo.toml中,例如,通过将以下行添加到该文件中:

To use crates from crates.io, you need to add them to your Cargo.toml, for example by adding the following lines to that file:

[dependencies]
text_io = "0.1"

这篇关于“宏未定义";当使用scan读取u8时!()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆