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); }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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}"); }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly