• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Rust格式输出

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

格式输出由一系列定义在 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/



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
MatLab矩阵计算发布时间:2022-07-18
下一篇:
MATLAB函数参考发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap