zoukankan      html  css  js  c++  java
  • printf的转换说明要注意的几点

    -   // 左对齐,默认右对齐

    + // 显示符号,正数显示 + ,负数显示 -

    空格 // 正数显示空格,负数显示 -

    %%  // 打印 %

    0   // 不足宽度的,在前面补 0

     1 #include <stdio.h>
     2 #define BLURB "Authentic imitation!"
     3 
     4 int main(void)
     5 {
     6     printf("[%2s]
    ",BLURB);
     7     printf("[%24s]
    ",BLURB);
     8     printf("[%24.5s]
    ",BLURB);
     9     /*
    10      * 精度限制了待打印字符的个数
    11      * .5 告诉 printf()只打印5个字符
    12      * 另外,- 标记使得文本左对齐
    13      */
    14     printf("[%-24.5s]
    ",BLURB);
    15 
    16     return 0;
    17 }

     Result:

    [Authentic imitation!]
    [    Authentic imitation!]
    [                   Authe]
    [Authe                   ]

    转换说明(conversion specification):

      把二进制格式存储在计算机中值转换成一系列字符以便于显示。

    例如:

    数字76,在计算机内部存储格式是 0100 1100 

    %d 转换说明将 0100 1100 转换成字符 7 和 6,并显示为 76

    %x转换说明将  0100 1100 转换成十六进制记数法 4c

    %c转换说明将  0100 1100 转换成字符 L

  • 相关阅读:
    Spark Streaming ---没用
    spark-streaming笔记 ---没用
    zookeeper笔记 ---没用
    远程调试笔记 ---没用
    远程仓库
    git之时光机穿梭
    分布式版本控制系统 VS 集中式
    Map与WeakMap
    set与weakset
    Genarator生成器
  • 原文地址:https://www.cnblogs.com/luwudang/p/9690000.html
Copyright © 2011-2022 走看看