Rust 中使用 std::io 处理输入并解析布尔值:错误处理和修复
The error message suggests that there's an issue with parsing a boolean value from the input. To fix this, you can add error handling for the parse method.
Replace this line:
let row: Vec<bool> = lines.next().unwrap().split_whitespace().map(|x| x.parse().unwrap()).collect();
With this line:
let row: Vec<bool> = lines.next().unwrap().split_whitespace().map(|x| x.parse().unwrap_or(false)).collect();
This change will set the value to false if the parsing fails, instead of panicking with the unwrap method.
原文地址: https://www.cveoy.top/t/topic/jxRJ 著作权归作者所有。请勿转载和采集!