#include<iostream>
using namespace std;
void main()
{
char str1[] = "我是"; //默认是GB2312编码,一个字节表示字母,两个字节表示汉字
cout << sizeof(str1) << endl; //输出 5
char str2[] = "aa我是"; //
cout << sizeof(str2) << endl; //输出 7
wchar_t str3[] = L"aa我是";
cout << sizeof(str3) << endl; //输出 10 '\n'也是采用unicode编码 //加上了L后,使用定长编码,所有字符用2个字节表示 wchar_t 宽字节字符,就是unicode编码
system("pause");
}
visual studio 2015默认采用GB2312编码,即:一个字节表示字母,两个字节表示汉字
加上L后,采用unicode编码,即定长码,所有字母及汉字采用两个字节编码
import sys
print(sys.getdefaultencoding()) # 默认是utf-8编码
with open('a.txt','w') as f:
f.write('我是aa\n') # 如果仅仅含有字符,使用utf-8编码
# 如果既含有字符,又含有汉字,使用ANSI,表示不同的系统采用不同的编码。windows采用的是GB2312