字符串前面的“L”在 C++ 中是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6384118/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does the 'L' in front a string mean in C++?
提问by Kang Min Yoo
this->textBox1->Name = L"textBox1";
Although it seems to work without the L
, what is the purpose of the prefix? The way it is used doesn't even make sense to a hardcore C programmer.
虽然它似乎没有L
,前缀的目的是什么?它的使用方式对铁杆 C 程序员来说甚至没有意义。
采纳答案by Gleno
回答by saidox
'L' means wchar_t
, which, as opposed to a normal character, requires 16-bits of storage rather than 8-bits. Here's an example:
'L' 表示wchar_t
,与普通字符相反,它需要 16 位存储而不是 8 位。下面是一个例子:
"A" = 41
"ABC" = 41 42 43
L"A" = 00 41
L"ABC" = 00 41 00 42 00 43
A wchar_t
is twice big as a simple char. In daily use you don't need to use wchar_t, but if you are using windows.h you are going to need it.
Awchar_t
是简单字符的两倍大。在日常使用中,您不需要使用 wchar_t,但是如果您使用 windows.h,您将需要它。
回答by karadoc
It means the text is stored as wchar_t
characters rather than plain old char
characters.
这意味着文本存储为wchar_t
字符而不是普通的旧char
字符。
(I originally said it meant unicode. I was wrong about that. But it can be used for unicode.)
(我最初说这意味着 unicode。我错了。但它可以用于 unicode。)
回答by Bo Persson
It means that it is a wide character, wchar_t
.
这意味着它是一个宽字符,wchar_t
.
Similar to 1L
being a long value.
类似于1L
长值。
回答by R. Martinho Fernandes
It means it's an array of wide characters (wchar_t
) instead of narrow characters (char
).
这意味着它是一个由宽字符 ( wchar_t
) 而不是窄字符 ( char
) 组成的数组。
It's a just a string of a different kind of character, not necessarily a Unicode string.
它只是一个不同类型字符的字符串,不一定是 Unicode 字符串。
回答by jdehaan
L is a prefix used for wide strings. Each character uses several bytes (depending on the size of wchar_t
). The encoding used is independent from this prefix. I mean it must not be necessarily UTF-16 unlike stated in other answers here.
L 是用于宽字符串的前缀。每个字符使用几个字节(取决于 的大小wchar_t
)。使用的编码独立于这个前缀。我的意思是它不一定是 UTF-16,不像这里其他答案中所述。