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

Comparing 2 wchar_t arrays

I'm sure this is sooo simple but I've come from a c# background where strings are easy and now I am making a small trip into the unmanaged world I am very confused. Essentially I am using EnumDisplayDevices to list the available devices, I want to…
john bowring
  • 178
  • 2
  • 2
  • 11
8
votes
1 answer

Using fgetws after setting a UTF-8 locale?

GCC 4.8, 5.1, 6.2 and Clang 3.8.1 on Ubuntu 16.10 with -std=c11, -std=c++11, -std=c++14, and -std=c++17 all exhibit this weird behaviour when using fgetws(buf, (int) bufsize, stdin) after setlocale(LC_ALL, "any_THING.utf8");. Example…
cat
  • 3,888
  • 5
  • 32
  • 61
8
votes
1 answer

No output when using `fprintf' after `fwprintf'

This just happened to me while testing a part of a bigger program that I isolated. The original function would remove non ascii characters from a string in a special manner that I needed, the thing is this program #include #include…
Iharob Al Asimi
  • 52,653
  • 6
  • 59
  • 97
8
votes
3 answers

Errors using TCHAR,cannot convert to wchar_t

I've been asked to add functionality to an existing old project but i cannot get it to build. It handles unicode strings but i get a lot of errors regarding the use of TCHAR.Specifically almost every error is TCHAR cannot be converted to or used as…
yiannis
  • 440
  • 1
  • 6
  • 19
8
votes
1 answer

wchar_t valgrind issue - Invalid read of size 8

I'm not able to figure out why Valgrind is printing Invalid read of size 8 when using wchar_t. I'm running a 64bit Ubuntu (3.5.0-25) system with valgrind-3.7.0 and gcc 4.7.2. #include #include #include #include…
Jose
  • 99
  • 1
  • 4
7
votes
3 answers

char vs wchar_t

I'm trying to print out a wchar_t* string. Code goes below: #include #include #include char *ascii_ = "中日友好"; //line-1 wchar_t *wchar_ = L"中日友好"; //line-2 int main() { printf("ascii_: %s\n", ascii_); //line-3 …
Alcott
  • 17,905
  • 32
  • 116
  • 173
7
votes
3 answers

Is there a wchar_t version for asprintf?

I need a C function which returns the final length of a formatted string so I can properly allocate the target string, rather than calculate the length myself. There is snprintf which does just this upon inability to write the entire string, but…
gheorghe1800
  • 251
  • 1
  • 6
7
votes
4 answers

Portable wchar_t in C++

Is there a portable wchar_t in C++? On Windows, its 2 bytes. On everything else is 4 bytes. I would like to use wstring in my application, but this will cause problems if I decide down the line to port it.
Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
7
votes
3 answers

How to convert wstring to wchar_t*? C++

I would like to convert wstring to wchar_t*. I have tried everything what i know, please help. I would like to convert wstring to wchar_t*.
Jones Jones
  • 119
  • 1
  • 2
  • 4
7
votes
2 answers

conflicts: definition of wchar_t string in C++ standard and Windows implementation?

From c++2003 2.13 A wide string literal has type “array of n const wchar_t” and has static storage duration, where n is the size of the string as defined below The size of a wide string literal is the total number of escape sequences,…
user534498
  • 3,926
  • 5
  • 27
  • 52
7
votes
3 answers

Is endian conversion required for wchar_t data?

In C/C++, if a multi-byte wide character (wchar_t) value is transmitted from a big-endian system to a little-endian system (or vice-versa), will it come out the same value on the other side? Or will the bytes need to be swapped?
An̲̳̳drew
  • 13,375
  • 13
  • 47
  • 46
7
votes
1 answer

Why there are no "unsigned wchar_t" and "signed wchar_t" types?

The signedness of char is not standardized. Hence there are signed char and unsigned char types. Therefore functions which work with single character must use the argument type which can hold both signed char and unsigned char (this type was chosen…
Igor Liferenko
  • 1,499
  • 1
  • 13
  • 28
7
votes
7 answers

Does the C++ standard mandate an encoding for wchar_t?

Here are some excerpts from my copy of the 2014 draft standard N4140 22.5 Standard code conversion facets [locale.stdcvt] 3 For each of the three code conversion facets codecvt_utf8, codecvt_utf16, and codecvt_utf8_utf16: (3.1) — Elem is the…
n. m. could be an AI
  • 112,515
  • 14
  • 128
  • 243
7
votes
3 answers

Deprecated conversion from string const. to wchar_t*

Hello I have a pump class that requires using a member variable that is a pointer to a wchar_t array containing the port address ie: "com9". The problem is that when I initialise this variable in the constructor my compiler flags up a depreciated…
Zac
  • 2,229
  • 9
  • 33
  • 41
7
votes
1 answer

Lowercase of Unicode character

I am working on a C++ project that need to get data from unicode text. I have a problem that I can't lower some unicode character. I use wchar_t to store unicode character which read from a unicode file. After that, I use _wcslwr to lower a wchar_t…
Nguyên Phan
  • 133
  • 1
  • 8
1 2
3
31 32