We can print as many text on the terminal as we want using println!()
macro. These text are known as string in Rust and must be written enclosed in double quotes only.
fn main() {
println!("hello, world");
println!("how are you?");
}
{}
within println!()
macro is used to substitute the values from associated arguments.
fn main() {
println!("hello, {}", "world");
println!("how are {}?", "you");
}
You can have more than one upto as many as you want substitution in println!()
macro. The order is important in argument. See the second println!()
as an example.
fn main() {
println!("{}, {}", "hello" "world");
println!("{} {} {}?", "how", "you", "are");
}
Labels: rust