In just five steps, we will explore command line I/O and formatting:
- Open a Terminal window (PowerShell on Windows) and run the cargo new hello-world command, which creates a new Rust project in a hello-world folder.
- Once created, change into the directory with cd hello-world and open src/main.rs with a Visual Studio Code. The default code generated by cargo looks like this:
fn main() { println!("Hello, world!");}
- Let's expand it! These are variations on the preceding traditional print statement, showing some formatting options, parameters, and writing on streams, among other things. Let's start with some common prints (and imports):
use std::io::{self, Write};use std::f64;fn main() { println!("Let's print some lines:"); ...