Format_print
Formatted Print
1. std::fmt
std::fmt2.格式化输出
2.1 使用占位符
format!("{1} {} {0} {}", 1, 2); // => "2 1 1 2"fn format_print() {
println!("\nFormat print test:");
let str1 = format!("Just a test with {}", "format!");
println!("{}", str1);
println!("{one} is {doing} by {two}",
one="Tim",
doing="beating",
two="Tom");
println!("{:?}", (12.0, 55));
println!("{:05}", 31);
println!("{} of {:b} people know binary, the other do not", 1, 2);
println!("Padding num with extra 0 {num:>0width$}", num=12, width=5);
}
/*Format print test:
Just a test with format!
Tim is beating by Tom
(12.0, 55)
00031
1 of 10 people know binary, the other do not
Padding num with extra 0 00012
*/1.2 参数类型
1.3 精度
2. Traits
Last updated