当前位置: 代码迷 >> 综合 >> rust:读取并显示文本文件
  详细解决方案

rust:读取并显示文本文件

热度:67   发布时间:2023-12-12 15:31:20.0

 直接上代码吧:

use std::io::Read;fn main() {let mut file = std::fs::File::open("data.txt").unwrap();let mut contents = String::new();file.read_to_string(&mut contents).unwrap();// print!("{}", contents);for s in contents.lines() {print!("->{}<-\n", s);}
}