当前位置:网站首页>C language char, wchar_ t, char16_ t, char32_ Relationship between T and character set
C language char, wchar_ t, char16_ t, char32_ Relationship between T and character set
2022-07-06 21:34:00 【landian004】
1,char It's not fixed in the standard 8 position , But it's fixed c/c++ Medium 1 byte !
But usually 8 position . And it's 8 When a , Share Signed and unsigned , When there is no sign 0-255, Yes when there is a symbol 0-127. When there is a symbol, it corresponds to Only ASCII Character set , because iso-8859-1 or windows1252 or EBCDIC yes 256 A character . Our computer is usually The signed , Which is the corresponding ASCII Character set .win,mac and linux You can verify ( How to verify ?)
2,wchar_t yes 16 Bit or 32 position (linux Is in the 32 position ,win Is in the 16 position ), So it's not portable .
wchar_t Also follow setlocale Functions are related , Must be used setlocale function , Its corresponding character set does not know to follow setlocale What kind of connection , second ,setlocale I don't know char16_t and char32_t Is there a connection ? in general , Because it is not portable , In less than wchar_t, And directly use the fixed width character set char16_t and char32_t.
3,char16_t Is to determine the 16 position , It's also certain utf16 Character set . and ucs-2 That's for sure 16 position ,utf16 It's not certain 16 position , It grows ( It can be 16 Bit and 32 position ).char16_t It can store all utf16 Of code units, instead of code points( That is, all characters ), stay utf16 The coding scheme exceeds 16 Characters with bit length are 2 individual code units To express . That is to say utf16 In excess 16 Bit long characters are 2 individual char16_t To express .
4,char32_t Is to determine the 32 position , affirmatory utf32 . But the disadvantage is that it wastes space !
5, however In practice , Out-of-service char16_t , char32_t, The reason is that there is no language and standard library this 2 Kind of c11 New types of output methods !! So I can only use wchar_t!!
char* str=" chinese "; // incorrect
wchar_t* str2 = L" chinese "; // Use this
char16_t str3 = u" chinese "; // No, wprintf Equal output function ! So it can't be used !
6, use char* str = " chinese "; printf("%s", str); It can also print correctly , But with strlen() Function length measurement is wrong , Should not use char* or const char* or char str[] To represent Chinese string . problem :char* str and printf( instead of wprintf) What is the reason why Chinese strings can also be correctly represented and printed ?
7,char and wchar_t Representation and printing of all Only console programs are used , When writing a graphical interface program, the corresponding library has the function of Chinese output in the interface , such as SDL in ? But when the console program expresses and prints Chinese , Although not wchar_t and wprintf and setlocale() Function still handles correctly , But the correct way is still to use wchar_t,setlocale(),wprintf These represent .
8,setlocale(LC_ALL, "zh-CN"); // "zh-CN" or “zh-CN.UTF-8" or "", this 3 Any representation will do , Recommended for portability "zh-CN" This kind of writing ( The actual test is "zh-CN.UTF-8" It's OK , It is case insensitive )."zh-CN" There are more expressions here . however setlocale The principle of is still unclear ??
The above is the review stage 1 Summary of .
边栏推荐
- Description of web function test
- HMS Core 机器学习服务打造同传翻译新“声”态,AI让国际交流更顺畅
- 039. (2.8) thoughts in the ward
- [interpretation of the paper] machine learning technology for Cataract Classification / classification
- How do I remove duplicates from the list- How to remove duplicates from a list?
- guava:Collections.unmodifiableXXX创建的collection并不immutable
- document.write()的用法-写入文本——修改样式、位置控制
- Caching strategies overview
- Aike AI frontier promotion (7.6)
- It's almost the new year, and my heart is lazy
猜你喜欢
It's not my boast. You haven't used this fairy idea plug-in!
968 edit distance
Aiko ai Frontier promotion (7.6)
Dialogue with Jia Yangqing, vice president of Alibaba: pursuing a big model is not a bad thing
[Li Kou brush questions] 32 Longest valid bracket
967- letter combination of telephone number
【论文解读】用于白内障分级/分类的机器学习技术
uni-app App端半屏连续扫码
Is it profitable to host an Olympic Games?
guava:Collections.unmodifiableXXX创建的collection并不immutable
随机推荐
2017 8th Blue Bridge Cup group a provincial tournament
MySQL - transaction details
【论文解读】用于白内障分级/分类的机器学习技术
El table table - get the row and column you click & the sort of El table and sort change, El table column and sort method & clear sort clearsort
SQL:存储过程和触发器~笔记
Tips for web development: skillfully use ThreadLocal to avoid layer by layer value transmission
中国白酒的5场大战
袁小林:安全不只是标准,更是沃尔沃不变的信仰和追求
Fzu 1686 dragon mystery repeated coverage
[sliding window] group B of the 9th Landbridge cup provincial tournament: log statistics
快讯:飞书玩家大会线上举行;微信支付推出“教培服务工具箱”
Acdreamoj1110 (multiple backpacks)
[go][reprint]vscode run a HelloWorld example after configuring go
Absolute primes (C language)
for循环中break与continue的区别——break-完全结束循环 & continue-终止本次循环
JPEG2000-Matlab源码实现
Swagger UI tutorial API document artifact
[Li Kou brush questions] 32 Longest valid bracket
This year, Jianzhi Tencent
MySQL - 事务(Transaction)详解