当前位置:网站首页>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 .
边栏推荐
- 分糖果
- 14年本科毕业,转行软件测试,薪资13.5K
- document.write()的用法-写入文本——修改样式、位置控制
- JS according to the Chinese Alphabet (province) or according to the English alphabet - Za sort &az sort
- ICML 2022 | Flowformer: 任务通用的线性复杂度Transformer
- What's the best way to get TFS to output each project to its own directory?
- How to implement common frameworks
- Common English vocabulary that every programmer must master (recommended Collection)
- JS操作dom元素(一)——获取DOM节点的六种方式
- FZU 1686 龙之谜 重复覆盖
猜你喜欢

袁小林:安全不只是标准,更是沃尔沃不变的信仰和追求

039. (2.8) thoughts in the ward

After working for 5 years, this experience is left when you reach P7. You have helped your friends get 10 offers

Swagger UI tutorial API document artifact

The difference between break and continue in the for loop -- break completely end the loop & continue terminate this loop

红杉中国,刚刚募资90亿美元

基于深度学习的参考帧生成

【深度学习】PyTorch 1.12发布,正式支持苹果M1芯片GPU加速,修复众多Bug

Is it profitable to host an Olympic Games?

【滑动窗口】第九届蓝桥杯省赛B组:日志统计
随机推荐
2017 8th Blue Bridge Cup group a provincial tournament
Web开发小妙招:巧用ThreadLocal规避层层传值
document.write()的用法-写入文本——修改样式、位置控制
Interviewer: what is the internal implementation of ordered collection in redis?
Aike AI frontier promotion (7.6)
It's almost the new year, and my heart is lazy
爱可可AI前沿推介(7.6)
字符串的使用方法之startwith()-以XX开头、endsWith()-以XX结尾、trim()-删除两端空格
语谱图怎么看
How to implement common frameworks
Thinking about agile development
OneNote in-depth evaluation: using resources, plug-ins, templates
Fzu 1686 dragon mystery repeated coverage
KDD 2022 | realize unified conversational recommendation through knowledge enhanced prompt learning
R语言做文本挖掘 Part4文本分类
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
Common English vocabulary that every programmer must master (recommended Collection)
3D人脸重建:从基础知识到识别/重建方法!
R language for text mining Part4 text classification
Yuan Xiaolin: safety is not only a standard, but also Volvo's unchanging belief and pursuit