Questions tagged [wchar-t]

`wchar_t` is a fundamental data type in the C and C++ programming languages, and it stands for "wide character". Its intended use is to hold any character value from "the system's character set".

wchar_t is the fundamental "wide character" data type in the C and C++ programming languages. Both language standards are intentionally vague on what it is for, specifying only that it can hold any character value "from the system's character set". There are conversion functions to and from the system's narrow, multibyte character encoding, a concept left equally vague (the functions are mbtowc() and wctomb()).

The fact that the C and C++ language standards are at once encoding-agnostic yet also provide for a way to represent an extended character set is the source of much confusion for people who expect explicit guarantees of certain fixed encodings (such as UTF-8 or UTF-32).

The practical use of the wchar_t type is considered debatable by some programmers.

479 questions
2
votes
1 answer

Converting wchar_t to Char

I need to convert: wchar_t arr[20][32] To char arr[20][32] The conversion is done in the DLL (written in C++) and I want the values of arr to be displayed to the user in Windows Forms (written in C#). Is it possible to display directly wchar_t…
jeevitha
  • 21
  • 2
2
votes
3 answers

basic_string UTF16 encoding to NSString

What is the best method to convert from a C++ basic_string object with UTF16 encoding to an Objective-C NSString object? Can I cast from wchar_t* to char* like so and still have stringWithCString use the string correctly? [NSString…
iEqualShane
  • 21
  • 1
  • 2
2
votes
1 answer

Can't read and echo back unicode input in C

I wrote the following code: #include #include int main() { wchar_t wc[80]; wscanf(L"%ls", &wc); wprintf(L"%ls", wc); return 0; } My terminal supports Unicode, compiled using gcc 8.2.1 on Linux.
i cant
  • 401
  • 2
  • 9
2
votes
1 answer

ctypes wintypes WCHAR String Additional White Spaces

Why is every character followed by a white space in the following? C++ DLL test.h: #ifndef TEST_DLL_H #define TEST_DLL_H #define EXPORT __declspec(dllexport) __stdcall #include #include namespace Test_DLL { struct…
Bruno
  • 1,329
  • 2
  • 15
  • 35
2
votes
3 answers

array of wchar_t

I would like to have an array of wchar_t's. The following works: char** stringArray; int maxWords = 3; stringArray = new char*[maxWords]; stringArray[0] = "I"; stringArray[1] = " Love "; stringArray[2] = "C++" but this does not wchar_t **…
Nemesis
  • 109
  • 1
  • 1
  • 8
2
votes
2 answers

Write wchar_t* to file - works only for some characters

I have methods which returns unicode texts and i need to write them into file but some characters are not written. I have the following: const wchar_t* getStandardText() { return L"test"; } const wchar_t* getUnicodeText() { return…
Erik Šťastný
  • 1,487
  • 1
  • 15
  • 41
2
votes
1 answer

Width of wide character strings

I need a function to determine columns needed for a wide-character string in different OS. In glibc there is a function wcswidth. It doesn't seem to be available in Windows. Are there alternatives to it in Windows that I can use? Or maybe there…
Seleznev Anton
  • 641
  • 5
  • 14
2
votes
2 answers

Convert UTF-32 wide char to UTF-16 wide char in Linux for Supplementary Plane characters

We have a C++ application deployed on RHEL using ICU. We have a situation where in we need to convert UChar* to wchar_t* on linux. We use u_strToWCS to perform the conversion. #include #include #include…
D3XT3R
  • 181
  • 2
  • 15
2
votes
3 answers

Compare C-string of types char* and wchar_t*

I have a key like: wchar_t key[] = L"764frtfg88fgt320nolmo098vfr"; and a char* row[i] returned by a query from a Database. I'd like to compare my Key with row[i]. I tried with wcscmp (key,row[i]) != 0) but it gives me an error. Any suggestions ?
A.Adil
  • 29
  • 1
  • 6
2
votes
1 answer

Why does `std::basic_ifstream` not work in c++11?

The following code works as expected. The source code, file "file.txt" and "out.txt" are all encoded with utf8. But it does not work when I change wchar_t to char16_t at the first line in main(). I've tried both gcc5.4 and clang8.0 with -std=c++11.…
kangshiyin
  • 9,681
  • 1
  • 17
  • 29
2
votes
1 answer

How to cast to `wint_t` and to `wchar_t`?

Are the standards saying that casting to wint_t and to wchar_t in the following two programs is guaranteed to be correct? #include #include int main(void) { setlocale(LC_CTYPE, ""); wint_t wc; wc = getwchar(); …
Igor Liferenko
  • 1,499
  • 1
  • 13
  • 28
2
votes
1 answer

Marshal wchar_t** from C++ to C# as an out parameter?

I have this function in a dll in C and I cannot change it: extern "C" SIBIO_MULTILANGUAGE_API_C DWORD getLabel(const char* const i_formName, const char* const i_fieldName, …
BugsFree
  • 540
  • 1
  • 6
  • 24
2
votes
1 answer

Inconsistency in definitions of fputwc(), putwc() and putwchar() in glibc

Why fputwc(), putwc() and putwchar() take argument of type wchar_t instead of wint_t? This contradicts corresponding non-wide character functions fputc(), putc() and putchar(), which take int, not char.
Igor Liferenko
  • 1,499
  • 1
  • 13
  • 28
2
votes
3 answers

Problem converting char to wchar_t (length wrong)

I am trying to create a simple datastructure that will make it easy to convert back and forth between ASCII strings and Unicode strings. My issue is that the length returned by the function mbstowcs is correct but the length returned by the…
Tyler
  • 155
  • 1
  • 8
2
votes
1 answer

Printing/writing wchar_t?

First off: I know there are similar topics for C++, but I am curious about standard C, and I don't believe my problem is related to previous problems. I am trying to implement Unicode support for a simple program which just asks the user to select a…
user966939
  • 692
  • 8
  • 27