小编uns*_*iot的帖子

如何将字符串连接到Rust中的字符串?

我已经尝试to_string在char上使用该方法但是&str当我需要时返回一个String.

string char rust

8
推荐指数
2
解决办法
6559
查看次数

将字符串与从输入读取的字符串进行比较在Rust中不匹配

在下面的代码中,我希望当用户输入"q"时打印消息"哇",但事实并非如此.

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input)
        .expect("failed to read line");

    if input == "q" {
       println!("wow") ;
    }
}
Run Code Online (Sandbox Code Playgroud)

为什么消息未按预期打印?

string io rust

1
推荐指数
1
解决办法
1969
查看次数

标签 统计

rust ×2

string ×2

char ×1

io ×1