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

how to tell if a wchar_t has a surrogate (UTF-16)?

I've seen a few other posts on this issue but was unable to find any details on how to determine programatically if a codepoint uses more than one 2-byte (on Windows) wchar_t. An example: const wchar_t* s2 = L"\U0002008A"; // The "Han"…
2
votes
1 answer

16 bit wchar_t support in linux and gcc

I'm working on a cross platform project that complies with the -fshort-wchar flag so the wchar_t type is 2 byte. On Windows that's fine but on Linux the means no libc functions like printf or fprintf. I've been looking for a good solution for some…
Daniel Miron
  • 460
  • 3
  • 14
2
votes
1 answer

Converting contents of a byte array to wchar_t*

I seem to be having an issue converting a byte array (containing the text from a word document) to a LPTSTR (wchar_t *) object. Every time the code executes, I am getting a bunch of unwanted Unicode characters returned. I figure it is because I am…
2
votes
2 answers

Using getCurrentDirectoryW Doesn't Read Non-locale Characters

I use the following code to read current directory in Windows 7. The current directory is C:\特斯塔敌人. The current locale is English(EN). I used getCurrentDirectoryW with the idea that it will properly read the directory path since the function is…
Izza
  • 2,389
  • 8
  • 38
  • 60
2
votes
2 answers

Getting rid of wchar_t size linker warning

I compile my Android NDK library with -fshort-wchar. I know the RTL assumes 4-byte wchar_t, I know what I'm doing, the library works. However, on every build linker gives me the following warning for every object file: ld.exe: warning: MyFile.o…
Seva Alekseyev
  • 59,826
  • 25
  • 160
  • 281
2
votes
2 answers

C string to wide C string

I'm sure this question gets asked a lot but I just want to make sure there's not a better way to do this. Basically, I have a const char* which points to a null-terminated C string. I have another function which expects a const wchar_t* pointing to…
user974967
  • 2,928
  • 10
  • 28
  • 45
2
votes
1 answer

Initialise wchar_t with dynamic length

first I have to mention, that I am an absolute C++ beginner, so don't throw any stones. I want to kill an external program with the help of ShellExecute and delete a log file as simple as possible. On linux I can use system (and it works perfect),…
Oliver
  • 2,864
  • 1
  • 16
  • 27
1
vote
3 answers

Vector won't store correct datatype (wchar_t instead of uint16_t)

I have some code from the net reading hyperspectral data (image, so lots of integers giving pixel intensity) into a vector. I used the code with success on a Linux system, but now I need the same on a windows system. I use Visual Studio…
SveinT
  • 703
  • 5
  • 10
1
vote
1 answer

C CSV API for unicode

I need a C API for manipulating CSV data that can work with unicode. I am aware of libcsv (sourceforge.net/projects/libcsv), but I don't think that will work for unicode (please correct me if I'm wrong) because don't see wchar_t being used. Please…
J Harri
  • 407
  • 2
  • 7
  • 15
1
vote
2 answers

C++ - How to store a Chinese character in a char or similar?

I am trying to store a Chinese character in a variable of type wchar_t and print out this character. However, the program incorrectly prints a ?. Here is my code. #include int main() { using std::wcout; using std::endl; …
Danhui Xu
  • 69
  • 10
1
vote
2 answers

wchar_t NUL in managed/unmanaged C++

I need to use this (unmanaged) C++ library. One of the methods has a wchar_t* as a parameter. Tried using it in C#, but all my attempts resulted in an error code 'invalid argument'. I wrote a managed C++ wrapper for it - same problem. Now I compared…
Stonehead
  • 366
  • 2
  • 12
1
vote
1 answer

C++ How to _wfindfirst and _wfindclose on Win64 Win32

I have a piece of code to run on Windows that uses char const for a filename: char const * filename _finddata_t fi; intptr_t n; if ((n = _findfirst(filename, &fi)) != -1) { _findclose(n); return TRUE; } Now I want this to use this code…
user3443063
  • 1,455
  • 4
  • 23
  • 37
1
vote
0 answers

Can Windows' std::wcout display UTF-16 wchar_t surrogate pairs as a unicode character?

[LIVE] \U0001F34C\U0002008A on cout : \U0001F34C\U0002008A on wcout : wcsnlen : 4 1 : 0xd83c 2 : 0xdf4c 3 : 0xd840 4 : 0xdc8a wcsrtombs to char on cout : Even though UCRT makes MSVC more compliant with…
sandthorn
  • 2,770
  • 1
  • 15
  • 59
1
vote
6 answers

wstringstream to LPWSTR

I have built up a string using wstringstream and need to assign it to a member of a struct of type LPWSTR. I try to use my_stringstream.str().c_str() but get the following compile time error: cannot convert from 'const wchar_t *' to 'LPWSTR' How…
PCL
  • 421
  • 2
  • 7
  • 15
1
vote
2 answers

Wide character input using fgetwc() and fread()

When reading a wide character from a FILE stream, can fgetwc() and fread() be used interchangeably? It's tempting to assume that fgetwc() might work like this: wint_t fgetwc(FILE *src) { wchar_t c; size_t n_bytes = fread(&c, sizeof (wchar_t), 1,…
AJ Tan
  • 193
  • 7