Questions tagged [widechar]

widechar is a generic name for character sets wider than ASCII

The term widechar is a generic name for character sets wider than 8 bits. Generally this means some (unspecified) 16 or 32 bit Unicode encoding.

203 questions
4
votes
2 answers

Converting C++ std::wstring to utf8 with std::codecvt_xxx

C++11 has tools to convert wide char strings std::wstring from/to utf8 representation: std::codecvt, std::codecvt_utf8, std::codecvt_utf8_utf16 etc. Which one is usable by Windows app to convert regular wide char Windows strings std::wstring to utf8…
Victor Mezrin
  • 2,797
  • 2
  • 32
  • 48
4
votes
4 answers

"Incompatible pointer type" compiler warning for 4th argument of qsort

I'm trying to use the standard library's qsort to sort an array of wide characters: wchar_t a = L'a'; wchar_t a1 = L'ä'; wchar_t b = L'z'; wchar_t chararray[] = {b, a, a1}; length = wcslen(chararray); qsort(chararray, length, sizeof(wchar_t),…
chryss
  • 7,459
  • 37
  • 46
4
votes
1 answer

Why does wcwidth return -1 with a sign that I can print on the terminal?

Why does here wcwidth return "-1" (not a printable wide character) width "Ԥ" (0x0524)? #include #include #include int wcwidth(wchar_t wc); int main() { setlocale(LC_CTYPE, ""); wchar_t wc1 = L'合'; // 0x5408 …
sid_com
  • 24,137
  • 26
  • 96
  • 187
4
votes
2 answers

Trouble comparing UTF-8 characters using wchar.h

I am in the process of making a small program that reads a file, that contains UTF-8 elements, char by char. After reading a char it compares it with a few other characters and if there is a match it replaces the character in the file with an…
Eternal_Light
  • 676
  • 1
  • 7
  • 21
3
votes
1 answer

Why does printing this wide character string crash on windows?

I stumbled upon a problem while going through some unit tests, and I am not entirely sure why the following simple example crashes on the line with sprintf (Using Windows with Visual Studio 2019). #include #include int…
Julius
  • 1,155
  • 9
  • 19
3
votes
0 answers

May wchar_t be promoted to wint_t?

I see one contradiction of glibc reference and Amendment 1 to C90. The quote from glibc reference says that wchar_t may be promoted to wint_t: if wchar_t is defined as char the type wint_t must be defined as int due to the parameter promotion But…
Igor Liferenko
  • 1,499
  • 1
  • 13
  • 28
3
votes
0 answers

C++ - using Unicode in winconsole

I was trying to properly handle unicode input/output in winconsole (Polish Windows 10) using std::wcin, std::wcout, std::wstring, etc. I am using Visual Studio 2015 and Character Set in Property Pages is set to Unicode. After some search and couple…
PKua
  • 463
  • 3
  • 15
3
votes
1 answer

Why functions from wctype.h do not work without setlocale()?

My setup: glibc 2.24, gcc 6.2.0, UTF-8 environment. Consider the following example: #include #include #include int main(void) { setlocale(LC_CTYPE, "en_US.UTF-8"); wchar_t wc = L'я'; /* 00000100 01001111 */ if…
Igor Liferenko
  • 1,499
  • 1
  • 13
  • 28
3
votes
2 answers

Why perror() changes orientation of stream when it is redirected?

The standard says that: The perror() function shall not change the orientation of the standard error stream. This is the implementation of perror() in GNU libc. Following are the tests when stderr is wide-oriented, multibyte-oriented and not…
Igor Liferenko
  • 1,499
  • 1
  • 13
  • 28
3
votes
3 answers

Guarantee on size ordering on char, wchar_t, char16_t, char32_t

Does the C++ standard provide any guarantee on the ordering of the size in bytes of char, wchar_t, char16_t, char32_t? (any extract from the standard is welcome) For example do I have the guarantee that: sizeof(char) <= sizeof(wchar_t) <=…
Vincent
  • 57,703
  • 61
  • 205
  • 388
3
votes
2 answers

Combine two Bytes to WideChar

Is it possible to combine two Bytes to WideChar and if yes, then how? For example, letter "ē" in binary is 00010011 = 19 and 00000001 = 1, or 275 together. var WChar: WideChar; begin WChar := WideChar(275); // Result is "ē" var B1, B2:…
Little Helper
  • 2,419
  • 9
  • 37
  • 67
3
votes
4 answers

C++ File IO: Reading and Writing 16-bit Words

I want to write non-Unicode, 16-bit words to a file a read them back later. I know with a bit of byte manipulation I can do this in char mode using fstream::read() and fstream::write(). What do I need to do to use 16-bit words directly? For example,…
ThomasMcLeod
  • 7,603
  • 4
  • 42
  • 80
3
votes
3 answers

#define syntax with L identifier

#define CONST_FILENAME "okay.dat" LPCWSTR lpFilename=L CONST_FILENAME; //obviously doesn't work Basically, how do I get the equivalent of: LPCWSTR lpFilename=L"okay.dat"; using #define?
IND000
  • 29
  • 3
2
votes
2 answers

Converting Japanese characters from wide characacter to multibyte using API WideChartoMultibyte gives '????'

In my MFC application I am reading Japanese characters from string table then converting it into multibyte using following code WCHAR wBuf[1024]; int rc; rc = LoadStringW(hInstance, iResourceID, wBuf, 1024); WideCharToMultiByte(1252,…
Rahul
  • 1,401
  • 4
  • 17
  • 33
2
votes
2 answers

Problem with printing wide character in c

Hello I want to print the letter 'å' which is 131 in extended ascii and as far as I can see has UTF-8 code 00E5 and 0x00E5 in UTF-16. However, in the code below the program prints 'Õ' which is not what I wanted. I do not know what I have done wrong.…
1 2
3
13 14