为什么货物生成的输出包含不可读的字符时生成失败?

问题描述 投票:1回答:1

我想,如文档中所描述来构建一个简单guessing-game

use std::io;
//use rand::Rng; is not included 

fn main() {
     println!("Guess the number!");
     let secret_number = rand::thread_rng().gen_range(1, 101);
     println!("The secret number is: {}", secret_number);
     println!("Please input your guess.");
     let mut guess = String::new();
     io::stdin().read_line(&mut guess)
          .expect("Failed to read line");
     println!("You guessed: {}", guess);
}

上面的代码将无法编译由于缺少rand::Rng库(附注注释)。

问题是,cargo build命令的结果包含不可读的字符:

enter image description here

我使用CentOS的7,防锈版本1.32.0和货物版本1.32.0。我能之前运行cargo-build后,以验证终端编码,它没有改变。

是否有人可以解释这种现象?

rust rust-cargo
1个回答
2
投票

您可以使用cargo build --color=never不使用的颜色。


为了帮助您解决问题,同时保持颜色,我们需要更多的信息。例如。您所使用的终端模拟器,你有什么语言环境,等等。

© www.soinside.com 2019 - 2024. All rights reserved.