zoukankan      html  css  js  c++  java
  • 格式化输出中的%s和%S的陷阱

    CStringA csa;
    CStringA csc;
    CString csb(L"131231111111");
    csa.Format("%s", csb);      // 只会输出1
    csc.Format("%S", csb);      // 会输出131231111111

    printf("%s ", csa.GetBuffer(0));
    printf("%s ", csc.GetBuffer(0));

    本意想输出131231111111,可是"%s"只会输出1,因为%s是按照ascill编码,而csb是unicode编码,unicode编码格式是一个"1"后会跟一个0x00,所以对于ascill来说,就认为字符串终止了.

    %s和%S在不同的环境下,含义不一样:

    s

    When used with printf functions, specifies a single-byte–character string; when used with wprintf functions, specifies a wide-character string. Characters are printed up to the first null character or until the precision value is reached

    S

    When used with printf functions, specifies a wide-character string; when used with wprintf functions, specifies a single-byte–character string. Characters are printed up to the first null character or until the precision value is reached.

  • 相关阅读:
    基于proteus的数字电路设计
    AXI4自定义FPGA外设理论基础
    FPGA 原语之一位全加器
    FPGA原语初步试验
    PS的流水灯设计分析
    vivado2019操作之约束文件
    http 笔记1
    编写有效用例-笔记
    接口测试学习积累1
    模拟器学习
  • 原文地址:https://www.cnblogs.com/ashooter/p/4474418.html
Copyright © 2011-2022 走看看