博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Rust 格式输出
阅读量:4567 次
发布时间:2019-06-08

本文共 964 字,大约阅读时间需要 3 分钟。

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

转载于:https://www.cnblogs.com/cxchanpin/p/7327598.html

你可能感兴趣的文章
判断连通图是否有环(并查集)
查看>>
汽车之家面试题2016
查看>>
POJ-数据结构-优先队列模板
查看>>
【HAOI2006】旅行(并查集暴力)
查看>>
css实现文本超出部分省略号显示
查看>>
留言板
查看>>
vue-router组件状态刷新消失的问题
查看>>
Android UI开发第十四篇——可以移动的悬浮框
查看>>
java8的一些用法
查看>>
(十)Hive分析窗口函数(二) NTILE,ROW_NUMBER,RANK,DENSE_RANK
查看>>
2018-11-19站立会议内容
查看>>
STM32 通用定时器相关寄存器
查看>>
【题解】1621. 未命名
查看>>
字符串加密算法
查看>>
Oracle的实例恢复解析
查看>>
UICollectionView cellForItemAt 不被调用
查看>>
巧用网盘托管私人Git项目
查看>>
python全栈脱产第19天------常用模块---shelve模块、xml模块、configparser模块、hashlib模块...
查看>>
[LeetCode] House Robber
查看>>
virtualbox中kali虚拟机安装增强功能
查看>>