This question already has answers here:
What exactly is the L prefix in C++?
(3 answers)
Why is letter L used to indicate wide chars strings?
(2 answers)
Closed 8 years ago.
I came across something I can't search for what it means.
#define DEFAULT_KEY L"text"
What does 'L' mean or do?
Other example that I found
wcscat(xpath, L"\\");
It means the string literal has type const wchar_t*, which is a type different that const char*. It is usually used to store Unicode strings.
Some APIs (particularly the Windows API) use this type all over the place.
The L prefix denotes a wide character/string literal; i.e., it is of type wchar_t instead of char. Unicode based programs typically use wide strings, while ANSI/ASCII based programs typically do not.
Related
This question already has answers here:
Using Emoji literals in Clojure source
(2 answers)
Closed 4 years ago.
I'm trying to create a Unicode character for U+20BB7, but I can't seem to figure out a way.
\uD842\uDFB7
The above doesn't work. I'm starting to think that you can't use literal Unicode character syntax for characters above \uFFFF.
Are my only option to use a string instead?
"\uD842\uDFB7"
Since as a string it works?
You can only use a string here - you're basically trying to shove two 'char' (16bit) values into one. See [1]
Unicode Character Representations
The char data type (and therefore the value that a Character object
encapsulates) are based on the original Unicode specification, which
defined characters as fixed-width 16-bit entities. The Unicode
Standard has since been changed to allow for characters whose
representation requires more than 16 bits. The range of legal code
points is now U+0000 to U+10FFFF, known as Unicode scalar value.
(Refer to the definition of the U+n notation in the Unicode Standard.)
1: https://docs.oracle.com/javase/7/docs/api/java/lang/Character.html
This question already has answers here:
std::string and UTF-8 encoded unicode
(3 answers)
What encoding does std::string.c_str() use?
(2 answers)
Closed 8 years ago.
I think string can handle ANSI and wstring can handle Unicode16, is that right?
does C++ STL has class which can support UTF8 strings?
Just use std::string. It handles UTF-8 strings just fine.
Obviously you need to be aware that a codepoint can be 1 to 4 chars, and that a character can actually be any number of codepoints, but that rarely matters to you, and when it matters, std::wstring would have the same problems.
Big advantage is that std::string works the same everywhere. With std::wstring, different implementations use 16 bit or 32 bit numbers with very different meanings, there are problems with byte ordering and so on.
This question already has answers here:
What does the 'L' in front a string mean in C++?
(7 answers)
Closed 8 years ago.
LPWSTR l = L"D:/MyFile.txt";
I've searched everywhere, but couldnt find the answer. Thank you!
Long Pointer to Wide Character String. And you didn't search everywhere cause 1st google hit on LPWSTR points to MSDN:
The LPWSTR type is a 32-bit pointer to a string of 16-bit Unicode characters, which MAY be null-terminated. The LPWSTR type specifies a pointer to a sequence of Unicode characters, which MAY be terminated by a null character (usually referred to as "null-terminated Unicode").
typedef wchar_t* LPWSTR, *PWSTR;
And L in front of the literal specifies how the literal should be understood. It's kind of like suffixes for numeric types e.g: 10u, 4.0f. Because type is W (wchar_t), the appropriate counterpart for a literal definition is L.
This question already has answers here:
What does \x mean in C/C++?
(7 answers)
strlen - the length of the string is sometimes increased by 1
(1 answer)
Closed 8 years ago.
I know that hex-decimal number is usually prefixed with 0x in C/C++ language.
For example, 0x5A means 90 in decimal.
But I saw an example code using single-quoted character with '\x'.
BYTE outputBuffer[index++] = '\x5A'; // instead of 0x5A
Is the meaning of '\x5A' exactly the same as 0x5A?
If so, why is there alternative way of hex-decimal notation?
For a character, both are quite equal.
But only one can be mixed into a string with other normal characters. "ABC\x5A"
And only one can be used to initialize a large integral type: long long x = 0x1234567812345678LL;
This question already has answers here:
Multicharacter literal in C and C++
(6 answers)
What do single quotes do in C++ when used on multiple characters?
(5 answers)
Closed 9 years ago.
C++ seems to allow up to four characters to be held in single quotes, such as:
char c = 'abcd';
but at runtime, only the last value ('d') seems to be actually stored away. This behavior seems to happen for pairs of two, three, or four (at five the compiler finally calls uncle). But what's the deal with this design? I don't really see the logic in it.