标签:int 中文字符串 sizeof 字符串 printf 文字 cpp 中文 local
#include <stdlib.h>
#include <stdio.h>
#include <locale.h>
void main(){
printf("你好天朝"); //unicode 编码会输出乱码:浣犲ソ澶╂湞
//用多字符集编码不会乱码
char str[20] = "你好中国";
printf("%s\n",str); //unicode 编码会输出乱码:姴銈芥稉顓炩偓
printf("%c%c\n",str[0],str[1]); //两个字节为一个汉字,所以输出 “你”
}
void main111(){
wchar_t ch = L‘我‘; //L是宽字符或字符串的标志
printf("%d \n",sizeof(ch)); //2
setlocale(LC_ALL,"chs"); //设置成本地简体中文
wprintf(L"%wc \n",ch); //L是宽字符或字符串的标志,输出一个汉字
wchar_t str[100] = L"我是一只小小小鸟"; // 不加L会报错哦
wprintf(L"%s ",str); //正确输出中文字符串
}
标签:int 中文字符串 sizeof 字符串 printf 文字 cpp 中文 local
原文地址:https://www.cnblogs.com/luoxuw/p/11334855.html