C++问题:wchar_t a[] = L"bh" ; 这句话中的L是什么意思?
答案:3 悬赏:50 手机版
解决时间 2021-11-19 06:34
- 提问者网友:嘚啵嘚啵
- 2021-11-18 13:04
C++问题:wchar_t a[] = L"bh" ; 这句话中的L是什么意思?
最佳答案
- 五星知识达人网友:掌灯师
- 2021-11-18 13:54
就是使用UNICODE编码的意思。
"bh"在内存中是三个字节:0x62,0x68,0x00
L"bh"在内存中是六个字节:0x0062,0x0068,0x0000,UNICODE下(UCS2)每个字符占用两个字节(即一个wchar_t)。追问我知道功能是这样,可这不符合语法啊追答C++标准里面就是这么定的:
C++2003
$2.13.2 Character literals
$2.13.2/1
A character literal is one or more characters enclosed in single quotes, as in ’x’, optionally preceded by the letter L, as in L’x’.
$2.13.2/2
A character literal that begins with the letter L, such as L’x’, is a wide-character literal. A wide-character literal has type wchar_t.
Rationale for International Standard Programming Languages C
$6.4.5 String literals
An L prefix distinguishes wide string literals. A prefix rather than a suffix notation was adopted so that a translator can know at the start of the processing of a string literal whether it is dealing with ordinary or wide characters.追问真是一针见血
"bh"在内存中是三个字节:0x62,0x68,0x00
L"bh"在内存中是六个字节:0x0062,0x0068,0x0000,UNICODE下(UCS2)每个字符占用两个字节(即一个wchar_t)。追问我知道功能是这样,可这不符合语法啊追答C++标准里面就是这么定的:
C++2003
$2.13.2 Character literals
$2.13.2/1
A character literal is one or more characters enclosed in single quotes, as in ’x’, optionally preceded by the letter L, as in L’x’.
$2.13.2/2
A character literal that begins with the letter L, such as L’x’, is a wide-character literal. A wide-character literal has type wchar_t.
Rationale for International Standard Programming Languages C
$6.4.5 String literals
An L prefix distinguishes wide string literals. A prefix rather than a suffix notation was adopted so that a translator can know at the start of the processing of a string literal whether it is dealing with ordinary or wide characters.追问真是一针见血
全部回答
- 1楼网友:枭雄戏美人
- 2021-11-18 14:27
L 表示宽字符追问我知道功能是这样,可这不符合语法啊追答完全符合语法,不管哪个编译器都能过追问符合什么语法?难道是数据类型的强制转换?
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯