当前位置:网站首页>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 .
边栏推荐
- R language for text mining Part4 text classification
- C语言:#if、#def和#ifndef综合应用
- 技术分享 | 抓包分析 TCP 协议
- [MySQL] basic use of cursor
- R语言做文本挖掘 Part4文本分类
- Replace Internet TV set-top box application through digital TV and broadband network
- JS get array subscript through array content
- KDD 2022 | 通过知识增强的提示学习实现统一的对话式推荐
- js通过数组内容来获取数组下标
- Four common ways and performance comparison of ArrayList de duplication (jmh performance analysis)
猜你喜欢
Z function (extended KMP)
Reviewer dis's whole research direction is not just reviewing my manuscript. What should I do?
2022菲尔兹奖揭晓!首位韩裔许埈珥上榜,四位80后得奖,乌克兰女数学家成史上唯二获奖女性
It's not my boast. You haven't used this fairy idea plug-in!
【Redis设计与实现】第一部分 :Redis数据结构和对象 总结
Aike AI frontier promotion (7.6)
Study notes of grain Mall - phase I: Project Introduction
Seven original sins of embedded development
【力扣刷题】一维动态规划记录(53零钱兑换、300最长递增子序列、53最大子数组和)
[Li Kou brush questions] 32 Longest valid bracket
随机推荐
El table table - sortable sorting & disordered sorting when decimal and% appear
After working for 5 years, this experience is left when you reach P7. You have helped your friends get 10 offers
WEB功能测试说明
ICML 2022 | flowformer: task generic linear complexity transformer
Start the embedded room: system startup with limited resources
el-table表格——获取单击的是第几行和第几列 & 表格排序之el-table与sort-change、el-table-column与sort-method & 清除排序-clearSort
麦趣尔砸了小众奶招牌
Z function (extended KMP)
JS get array subscript through array content
ROS error: could not find a package configuration file provided by "move_base“
【滑动窗口】第九届蓝桥杯省赛B组:日志统计
[redis design and implementation] part I: summary of redis data structure and objects
JS operation DOM element (I) -- six ways to obtain DOM nodes
JS according to the Chinese Alphabet (province) or according to the English alphabet - Za sort &az sort
Swagger UI tutorial API document artifact
el-table表格——sortable排序 & 出现小数、%时排序错乱
Reference frame generation based on deep learning
It's not my boast. You haven't used this fairy idea plug-in!
Data Lake (VIII): Iceberg data storage format
966 minimum path sum