zoukankan      html  css  js  c++  java
  • 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/


  • 相关阅读:
    我们的回忆

    出差
    恍惚
    七夕
    K8S命令(一)——Node相关
    K8S命令(二)——查询相关
    [转载]为什么你应该(从现在开始就)写博客
    替代JDK日期的开源项目:jodatime
    使用getElementById获取xml中的指定元素
  • 原文地址:https://www.cnblogs.com/cxchanpin/p/7327598.html
Copyright © 2011-2022 走看看