C语言 宽字符串

/* 宽字符串的打印 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
#include <locale.h>   /* 宽字符转换 */

void show(void)
{
    const wchar_t * pw = L"今天天气还不错啊!";

    /*
    设计说明:
        如果打印中文字符,setlocale()是必须的
    */
    setlocale(LC_ALL, "zh_CN.UTF-8");

    /*
    知识补充:
        printf和wprintf不能混用,即一个程序中使用了printf, 就不使用wprintf,反之也是,既然printf输出char 和 wchar_t字符都可以,所以统一使用printf是最佳选择。
    */

    //printf打印宽字符串
    printf("--printf--[%ls]------\n", pw);
    printf("--printf--[%S]------\n", pw);

    ////wprintf打印宽字符串
    //wprintf(L"--wprintf--[%ls]------\n", pw);
    //wprintf(L"--wprintf--[%S]------\n", pw);
}

int main()
{
    show();
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/zhanggaofeng/p/11666054.html