We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
%
\n
fn main () { // print print!("print 🦀"); let year = 2022; print!("this year is {}", year); // 使用 \n 修复,末尾的 % 问题 ✅ print!("\n"); } /* $ rustc ./print.rs && ./print // print 🦀% // ??? Rust print! 这么多输出一个 % */
The text was updated successfully, but these errors were encountered:
https://www.runoob.com/rust/rust-println.html
println 后面还有一个 ! 符号,难道 Rust 函数之后都要加一个感叹号?
!
显然并不是这样, println 不是一个函数,而是一个宏规则;
不是
函数
而是
宏规则
Rust 输出文字的方式主要有两种:println!() 和 print!()。
println!()
print!()
这两个"函数"都是向命令行输出字符串的方法,区别仅在于前者会在输出的最后附加输出一个换行符。
当用这两个"函数"输出信息的时候,第一个参数是格式字符串,后面是一串可变参数,对应着格式字符串中的"占位符",这一点与 C 语言中的 printf 函数很相似。
格式字符串
一串可变参数
占位符
printf
但是,Rust 中格式字符串中的占位符不是 "% + 字母" 的形式,而是一对 {}。
% + 字母
{}
Sorry, something went wrong.
No branches or pull requests
Rust print! 这么多输出一个
%
符号使用
\n
修复,末尾的%
问题 ✅The text was updated successfully, but these errors were encountered: