Rust input/output: Difference between revisions
From wikinotes
Line 31: | Line 31: | ||
print!("START\n{}\nFINISH", input.join("\n")); | print!("START\n{}\nFINISH", input.join("\n")); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{ TODO | | |||
read from stdin, checking if it's a tty or a pipe }} | |||
</blockquote><!-- Stdin, Stdout, Stderr --> | </blockquote><!-- Stdin, Stdout, Stderr --> | ||
Revision as of 06:32, 9 February 2023
Documentation
std::fs
https://doc.rust-lang.org/std/fs/index.html
Stdin, Stdout, Stderr
println!("out"); // write to stdout eprintln!("err"); // write to stderrread from stdin (wait indefinitely if nothing is written)
use std::io; use std::io::BufRead; let mut input: Vec<String> = Vec::new(); let stdin = io::stdin(); let handle = stdin.lock(); for result in handle.lines() { match result { Ok(line) => input.push(line), Err(_) => break, } } print!("START\n{}\nFINISH", input.join("\n"));TODO:
read from stdin, checking if it's a tty or a pipe
User Input
let name = String::new(); io::stdin().read_line(&mut name);