Rust 格式输出

格式输出由一系列定义在 std::fmt 中的宏提供。


包括:

format! : 输出格式化的字符串。
print!  : 输出格式化的字符串到控制台(终端)
println!: 增加一个换行,输出格式化的字符串到控制台(终端)


 
println!("Guess the number!");
 
输出:

Guess the number!

 
println!("{} days", 31);
 
输出:

31 days


 
println!("{0}, this is {1}. {1}, this is {0}", "Alice", "Bob");
 
输出:

Alice, this is Bob. Bob, this is Alice


 
println!("{subject} {verb} {object}",
             object="the lazy dog",
             subject="the quick brown fox",
             verb="jumps over");
 
输出:

the quick brown fox jumps over the lazy dog


 
println!("{} of {:b} people know binary, the other half don't", 1, 2);
 
输出:

1 of 10 people know binary, the other half don't


 
println!("{number:>width$}", number=1, width=6);
 
输出:

“     1”  // 引号是为了显示数字1的前面有五个空白字符而加上的,实际没有。


 
println!("{number:>0width$}", number=1, width=6);
 
输出:

000001


 
println!("My name is {0}, {1} {0}.”, "Bond","James");
 

输出:

My name is Bond, James Bond



更多语法:http://doc.rust-lang.org/std/fmt/


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值