R16: Files Descriptors Flashcards
1
Q
Reading the Argument Values
A
use std::env;
fn main() {
let args: Vec<String> = env::args().collect();</String>
let query = &args[1]; let file_path = &args[2]; println!("Searching for {}", query); println!("In file {}", file_path); }
2
Q
Reading a File
A
use std::env;
use std::fs;
fn main() {
// –snip–
println!(“In file {}”, file_path);
let contents = fs::read_to_string(file_path) .expect("Should have been able to read the file"); println!("With text:\n{contents}"); }