How to get command line arguments in Rust?
Hello! I just started learning Rust and I have a problem. I'm writing a small console utility that should accept a filename and operation mode (e.g., "read" or "write") from the command line. In other languages, like Python, I just used sys.argv, and in C — argc/argv. But in Rust I can't figure out how to do it.
Here's what I tried:
```rust
fn main() {
let args = std::env::args();
println!("{:?}", args);
}
```
But it prints something strange: `Args { inner: ["target/debug/myapp", "test.txt", "read"] }`. How do I get individual strings instead of this weird object? And how do I check how many arguments were passed?
I need the program to work like this: `myapp test.txt read` — reads the file, and `myapp test.txt write` — writes to it. If the argument
No answers yet.
Log in to leave an answer