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
14
votes
2 answers

how does windows wchar_t handle unicode characters outside the basic multilingual plane?

I've looked at a number of other posts here and elsewhere (see below), but I still don't have a clear answer to this question: How does windows wchar_t handle unicode characters outside the basic multilingual plane? That is: many programmers…
vy32
  • 28,461
  • 37
  • 122
  • 246
14
votes
1 answer

char16_t printing

Recently I had a problem with porting a Windows application to Linux because of the wchar_t size difference between these platforms. I tried to use compiler switches, but there were problems with printing those characters (I presume that GCC wcout…
NoSenseEtAl
  • 28,205
  • 28
  • 128
  • 277
14
votes
2 answers

Which method is correct for Initializing a wchar_t string?

I am writing a program and I need to initialize a message buffer which will hold text. I am able to make it work, however I am writing below various ways used to initialize the strings in C and I want to understand the difference. Also, which is the…
Neon Flash
  • 3,113
  • 12
  • 58
  • 96
13
votes
5 answers

wchar_t is unsigned or signed

In this link unsigned wchar_t is typedefed as WCHAR. But I cant find this kind of typedef in my SDK winnt.h or mingw winnt.h. wchar_t is signed or unsigned? I am using WINAPIs in C language.
2vision2
  • 4,933
  • 16
  • 83
  • 164
12
votes
4 answers

cannot convert 'const char*' to 'LPCWSTR {aka const wchar_t*}'

I'm getting an error in my C++ code that I can't quite make sense of. The stripped down code bits are here: RS232Handle=OpenRS232("COM1", 9600); HANDLE OpenRS232(const char* ComName, DWORD BaudRate) { ComHandle=CreateFile(ComName,…
sci-guy
  • 2,394
  • 4
  • 25
  • 46
11
votes
5 answers

Convert wchar_t to int

how can I convert a wchar_t ('9') to a digit in the form of an int (9)? I have the following code where I check whether or not peek is a digit: if (iswdigit(peek)) { // store peek as numeric } Can I just subtract '0' or is there some Unicode…
Lasse Espeholt
  • 17,622
  • 5
  • 63
  • 99
11
votes
6 answers

isalpha equivalent for wchar_t

what is the equivalent function for isalpha or isalnum using wchar_t? wctype ? an example would be nice also thanks
lj8888
  • 367
  • 4
  • 8
10
votes
3 answers

how to convert char array to wchar_t array?

char cmd[40]; driver = FuncGetDrive(driver); sprintf_s(cmd, "%c:\\test.exe", driver); I cannot use cmd in sei.lpFile = cmad; so, how to convert char array to wchar_t array ?
pradeep
  • 3,005
  • 12
  • 42
  • 65
10
votes
3 answers

Does wide character input/output in C always read from / write to the correct (system default) encoding?

I'm primarily interested in the Unix-like systems (e.g., portable POSIX) as it seems like Windows does strange things for wide characters. Do the read and write wide character functions (like getwchar() and putwchar()) always "do the right thing",…
Quantumboredom
  • 1,426
  • 11
  • 19
10
votes
3 answers

How to initialize a wchar_t variable?

I am reading the book: C: In a Nutshell, and after reading the section Character Sets, which talks about wide characters, I wrote this program: #include #include #include int main() { wchar_t wc = '\x3b1'; …
Yishu Fang
  • 9,448
  • 21
  • 65
  • 102
9
votes
3 answers

Why is char neither signed or unsigned, but wchar_t is?

The following C++ program compiles without errors: void f(char){} void f(signed char){} void f(unsigned char){} int main(){} The wchar_t version of the same program does not: void f(wchar_t){} void f(signed wchar_t){} void f(unsigned…
Trevor Hickey
  • 36,288
  • 32
  • 162
  • 271
9
votes
3 answers

Why does the towlower() function not convert the Я to a lower-case я?

The function towlower() doesn't seem to work in Visual Studio 2012. Here's an example: #include #include #include #include #include using namespace std; int main() { _setmode(_fileno(stdout),…
Johnny Mnemonic
  • 3,822
  • 5
  • 21
  • 33
9
votes
2 answers

Reading/writing/printing UTF-8 in C++11

I have been exploring C++11's new Unicode functionality, and while other C++11 encoding questions have been very helpful, I have a question about the following code snippet from cppreference. The code writes and then immediately reads a text file…
Ephemera
  • 8,672
  • 8
  • 44
  • 84
9
votes
2 answers

Cross-platform unicode in C/C++: Which encoding to use?

I'm currently working on a hobby project (C/C++) which is supposed to work on both Windows and Linux, with full support for Unicode. Sadly, Windows and Linux use different encodings making our lives more difficult. In my code I'm trying to use the…
ErikKou
  • 165
  • 2
  • 6
8
votes
3 answers

Print wchar to Linux console?

My C program is pasted below. In bash, the program print "char is ", Ω is not printed. My locale are all en_US.utf8. #include #include #include int main() { int r; wchar_t myChar1 = L'Ω'; r = wprintf(L"char…
davy
  • 123
  • 1
  • 3
  • 8
1
2
3
31 32