format! 格式化文本并返回结果到字符串
print! 输出格式化文本到控制台
println! 输出格式化文本到控制台,并在行尾自动加换行
代码文件,format.rc
fn main()
{
fn main()
{
let hello = format!("hello {}", "world");
println!("{}", hello);
println!("hello {}", "format");
println!("hello {0}, this is a good {1},{0}", "format", "boy");
}
}
编译
rustc format.rc
执行
./format
输出结果
hello world
hello format
hello format, this is a good boy,format