Rust input/output: Difference between revisions

From wikinotes
No edit summary
Line 1: Line 1:
= print =
<blockquote>
<syntaxhighlight lang="rust">
println!("abc");
// string interpolation
println!("Hello, {}", "alex");
println!("{0}, {0}, see {1}?", "alex", "movie");
println!("{person}, see {thing}?", person="alex", thing="movie");
// formatting
println!("{:>4}", 2)            // "  2"  right align
println!("{:0>4}", 2)            // "0002"  right align, padded w/ zeros
println!("{var:>4}", var="boo")  // " boo"  right align
// type formatting
println!("{:X}", 1234)          // "4D2"  hex
println!("{:o}", 1234)          // "2322"  octal
</syntaxhighlight>
</blockquote><!-- print -->


= user input =
= user input =

Revision as of 00:56, 9 February 2023

user input

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