What does this string in c++ mean? [duplicate] - c++

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.

Related

How to use Unicode character literal for Han characters in Clojure [duplicate]

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

Dealing with Japanese characters [duplicate]

This question already has an answer here:
warning: multi-character character constant [-Wmultichar]
(1 answer)
Closed 5 years ago.
So I was reading 'Accelerated C++' and there I read about wchar_t, I Googled a Japanese character and threw in the following statement in my program:
wchar_t japs = 'の';
It gave me this error:
input.cpp:20:20: warning: multi-character character constant [-Wmultichar]
wchar_t japs = 'の';
I don't know Japanese but I am clueless about what is happening here. Googled a bit, some solutions were talking about, it being a Linux issue, some solutions were talking about UTF-8 encoding.
Can someone really tell, what is actually happening? My environment in Ubuntu?
Your Editor supports Utf8. If you enter this character 'の' it will be encoded as a sequence of characters [ 0xe3, 0x81, 0xae ].
wchar_t is a typedef for a integer value. you should use the UTF8 encoding and store the characters in strings. e.g. char japs[] = "の";
If your terminal supports utf-8 (it normaly does) you can use japanese characters in c-strings, as you would use latin characters. bit keep in mind that one japanese character occupies three or more bytes in a c-string.
This type of string is called a multi-byte-string. if you like trouble you can convert a string with utf8 encoded characters to an array of wchar_t type. usualy each character will take 32bit. see "man mbstowcs".

Meaning of L near text in define [duplicate]

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.

C win32 api unicode to ascii [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How do you convert LPCWSTR to const char *?
I have a function that gets a LPCWSTR string for win32 api usage.
Now I have a function that sends data in ASCII to the IRC server.
So now I need to convert it to ASCII, I haven't found any solutions, I only found ways to convert ASCII to UNICODE.
WideCharToMultiByte converts from UNICODE to MBCS. If your original wide char string consisted only of characters which could be represented in ASCII, then this will result in a ASCII string.
You can also use wcstombs which internally calls WideCharToMultiByte.
Either way, you will get a LPSTR or char * (which are the same).

convert SYSTEMTIME to LPCWSTR [duplicate]

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
Is there a function like asctime_s() that works for SYSTEMTIME structures in windows?
I need to convert a type of SYSTEMTIME to a string. Then append the string product onto another string. Then finally convert the final string to type of LPCWSTR
All of the properties of the SYSTEMTIME are WORD types.
I think I need to convert the WORD types to wchar_t types and then concatenate them to get the string of SYSTEMTIME. How do I do this conversion and concatenation?
Once the final string has been built how can a LPCWSTR type be made from it?
Use GetTimeFormatEx or GetTimeFormat if you need to support Windows XP to format a SYSTEM time to a string.