widechar

What's the difference between printf(“%s”), printf(“%ls”), wprintf(“%s”), and wprintf(“%ls”)?

為{幸葍}努か 提交于 2019-11-30 13:45:44
问题 Consider this sample program: #include <cstdio> #include <cwchar> #include <string> int main() { std::string narrowstr = "narrow"; std::wstring widestr = L"wide"; printf("1 %s \n", narrowstr.c_str()); printf("2 %ls \n", widestr.c_str()); wprintf(L"3 %s \n", narrowstr.c_str()); wprintf(L"4 %ls \n", widestr.c_str()); return 0; } The output of this is: 1 narrow 2 wide I'm wondering: why 3 & 4 didn't print what the differences are between 1&3, and 2&4. does it make any difference if narrowstr is

C++: wide characters outputting incorrectly?

跟風遠走 提交于 2019-11-30 09:34:29
My code is basically this: wstring japan = L"日本"; wstring message = L"Welcome! Japan is "; message += japan; wprintf(message.c_str()); I'm wishing to use wide strings but I do not know how they're outputted, so I used wprintf. When I run something such as: ./widestr | hexdump The hexidecimal codepoints create this: 65 57 63 6c 6d 6f 21 65 4a 20 70 61 6e 61 69 20 20 73 3f 3f e W c l m o ! e J p a n a i s ? ? Why are they all jumped in order? I mean if the wprintf is wrong I still don't get why it'd output in such a specific jumbled order! edit: endianness or something? they seem to rotate each

Windows API: ANSI and Wide-Character Strings — Is it UTF8 or ASCII? UTF-16 or UCS-2 LE?

China☆狼群 提交于 2019-11-29 20:26:26
I'm not quite pro with encodings, but here's what I think I know (though it may be wrong): ASCII is a 7-bit, fixed-length encoding, with the characters you can find in ASCII charts. UTF8 is an 8-bit, variable-length encoding. All characters can be written in UTF8. UCS-2 LE/BE are fixed-length, 16-bit encodings that support most common characters. UTF-16 is a 16-bit, variable-length encoding. All characters can be written in UTF16. Are those above all correct? Now, for the questions: Do the Windows "A" functions (like SetWindowTextA ) take in ASCII strings? Or "multi-byte strings" (more

C++: wide characters outputting incorrectly?

╄→尐↘猪︶ㄣ 提交于 2019-11-29 15:14:04
问题 My code is basically this: wstring japan = L"日本"; wstring message = L"Welcome! Japan is "; message += japan; wprintf(message.c_str()); I'm wishing to use wide strings but I do not know how they're outputted, so I used wprintf. When I run something such as: ./widestr | hexdump The hexidecimal codepoints create this: 65 57 63 6c 6d 6f 21 65 4a 20 70 61 6e 61 69 20 20 73 3f 3f e W c l m o ! e J p a n a i s ? ? Why are they all jumped in order? I mean if the wprintf is wrong I still don't get why

Windows API: ANSI and Wide-Character Strings — Is it UTF8 or ASCII? UTF-16 or UCS-2 LE?

岁酱吖の 提交于 2019-11-28 17:06:57
问题 I'm not quite pro with encodings, but here's what I think I know (though it may be wrong): ASCII is a 7-bit, fixed-length encoding, with the characters you can find in ASCII charts. UTF8 is an 8-bit, variable-length encoding. All characters can be written in UTF8. UCS-2 LE/BE are fixed-length, 16-bit encodings that support most common characters. UTF-16 is a 16-bit, variable-length encoding. All characters can be written in UTF16. Are those above all correct? Now, for the questions: Do the

What is the difference between WideChar and AnsiChar?

大兔子大兔子 提交于 2019-11-28 10:09:26
I'm upgrading some ancient (from 2003) Delphi code to Delphi Architect XE and I'm running into a few problems. I am getting a number of errors where there are incompatible types. These errors don't happen in Delphi 6 so I must assume that this is because things have been upgraded. I honestly don't know what the difference between PAnsiChar and PWideChar is, but Delphi sure knows the difference and won't let me compile. If I knew what the differences were maybe I could figure out which to use or how to fix this. The short: prior to Delphi 2009 the native string type in Delphi used to be ANSI

What is a “wide character string” in C language?

为君一笑 提交于 2019-11-27 07:17:15
I came across this in the book: wscanf(L"%lf", &variable); where the first parameter is of type of wchar_t * . This s different from scanf("%lf", &variable); where the first parameter is of type char * . So what is the difference than. I have never heard "wide character string" before. I have heard something called Raw String Literals which is printing the string as it is (no need for things like escape sequences) but that was not in C. The exact nature of wide characters is (purposefully) left implementation defined. When they first invented the concept of wchar_t , ISO 10646 and Unicode were

Why does the Java char primitive take up 2 bytes of memory?

纵然是瞬间 提交于 2019-11-27 03:57:17
Is there any reason why Java char primitive data type is 2 bytes unlike C which is 1 byte? Thanks When Java was originally designed, it was anticipated that any Unicode character would fit in 2 bytes (16 bits), so char and Character were designed accordingly. In fact, a Unicode character can now require up to 4 bytes. Thus, UTF-16, the internal Java encoding, requires supplementary characters use 2 code units. Characters in the Basic Multilingual Plane (the most common ones) still use 1. A Java char is used for each code unit. This Sun article explains it well. char in Java is UTF-16 encoded,

What is the difference between WideChar and AnsiChar?

会有一股神秘感。 提交于 2019-11-27 03:25:52
问题 I'm upgrading some ancient (from 2003) Delphi code to Delphi Architect XE and I'm running into a few problems. I am getting a number of errors where there are incompatible types. These errors don't happen in Delphi 6 so I must assume that this is because things have been upgraded. I honestly don't know what the difference between PAnsiChar and PWideChar is, but Delphi sure knows the difference and won't let me compile. If I knew what the differences were maybe I could figure out which to use

WideCharToMultiByte() vs. wcstombs()

一笑奈何 提交于 2019-11-27 01:57:34
问题 What is the difference between WideCharToMultiByte() and wcstombs() When to use which one? 回答1: In a nutshell: the WideCharToMultiByte function exposes the encodings/code pages used for the conversion in the parameter list, while wcstombs does not. This is a major PITA, as the standard does not define what encoding is to be used to produce the wchar_t , while you as a developer certainly need to know what encoding you are converting to/from. Apart from that, WideCharToMultiByte is of course a