当前位置:网站首页>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 .
边栏推荐
- string的底层实现
- WEB功能测试说明
- Caching strategies overview
- @GetMapping、@PostMapping 和 @RequestMapping详细区别附实战代码(全)
- Four common ways and performance comparison of ArrayList de duplication (jmh performance analysis)
- 039. (2.8) thoughts in the ward
- mysql根据两个字段去重
- Is this the feeling of being spoiled by bytes?
- Study notes of grain Mall - phase I: Project Introduction
- 3D人脸重建:从基础知识到识别/重建方法!
猜你喜欢
966 minimum path sum
【滑动窗口】第九届蓝桥杯省赛B组:日志统计
【Redis设计与实现】第一部分 :Redis数据结构和对象 总结
Why does MySQL index fail? When do I use indexes?
嵌入式开发的7大原罪
[in depth learning] pytorch 1.12 was released, officially supporting Apple M1 chip GPU acceleration and repairing many bugs
This year, Jianzhi Tencent
[interpretation of the paper] machine learning technology for Cataract Classification / classification
967- letter combination of telephone number
3D人脸重建:从基础知识到识别/重建方法!
随机推荐
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
numpy 下载安装
[sliding window] group B of the 9th Landbridge cup provincial tournament: log statistics
JS according to the Chinese Alphabet (province) or according to the English alphabet - Za sort &az sort
Replace Internet TV set-top box application through digital TV and broadband network
SDL2来源分析7:演出(SDL_RenderPresent())
The biggest pain point of traffic management - the resource utilization rate cannot go up
js中,字符串和数组互转(一)——字符串转为数组的方法
C语言:#if、#def和#ifndef综合应用
The use method of string is startwith () - start with XX, endswith () - end with XX, trim () - delete spaces at both ends
ICML 2022 | Flowformer: 任务通用的线性复杂度Transformer
[in depth learning] pytorch 1.12 was released, officially supporting Apple M1 chip GPU acceleration and repairing many bugs
Comparison between multithreaded CAS and synchronized
After working for 5 years, this experience is left when you reach P7. You have helped your friends get 10 offers
The underlying implementation of string
麦趣尔砸了小众奶招牌
Shake Sound poussera l'application indépendante de plantation d'herbe "louable", les octets ne peuvent pas oublier le petit livre rouge?
968 edit distance
Fastjson parses JSON strings (deserialized to list, map)
KDD 2022 | 通过知识增强的提示学习实现统一的对话式推荐