Rust IO reading numbers from stdin

⚓ Rust    📅 2025-10-09    👤 surdeus    👁️ 5      

surdeus

Hi. What is the best way to do something like this

int a, b;
std::cin >> a >> b;

in rust?
This is my current solution

let mut s = String::new();
io::stdin()
   .read_line(&mut s)
   .unwrap();

let (a,b ): (i32, i32) = {
    let x: Vec<_> = s.trim().split(' ').collect();
    (x[0].parse().unwrap(), x[1].parse().unwrap())
};

This is for competetive programming so all the data is correct.

4 posts - 2 participants

Read full topic

🏷️ Rust_feed