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
1
vote
1 answer

wchar_t array size issue with wcscpy_s

I'm confused with a size issue. Running the following code throws an exception at runtime. Specifically it seems to appear at end, and the text still be pasted with success. Due to my limited skills I'm not able to interpret the exception…
Bogey Jammer
  • 638
  • 2
  • 8
  • 23
1
vote
1 answer

Unresolved external symbol when using QString with wchar_t

The following code fails to link in Visual Studio: #include int main(int argc, char *argv[]) { const auto qstr = QString::fromWCharArray(L"Hello world!"); auto wstr = new wchar_t[qstr.length() + 1]; const auto wlen =…
cbuchart
  • 10,847
  • 9
  • 53
  • 93
1
vote
1 answer

Convert Swift String to wchar_t

For context: I'm trying to use the very handy LibXL. I've used it with success in Obj-C and C++ but am now trying to port over to Swift. In order to better support Unicode, I need to sent all strings to the LibXL api as wchar_t*. So, for this…
Todd
  • 1,770
  • 1
  • 17
  • 42
1
vote
2 answers

How am I allowed to workaround DOS functions that used strings containing accented characters (ASCII to UTF-8)?

I was writing a SW where I wanted to use an old C code written in the early '80. This code did some conversion on strings. It also used the accented characters that, at that time (DOS), were coded in the ASCII table (codes bigger than 127). Now the…
Sir Jo Black
  • 2,024
  • 2
  • 15
  • 22
1
vote
1 answer

Problems with wchar and registry entry

So I want to add a string to registry, since the registry strings are to written NULL terminated my string contains a null char in various places. This is what my string looks like. char names[550] =…
qwn
  • 347
  • 3
  • 15
1
vote
1 answer

GetFileAttributeW fails for non-ASCII characters

So I am trying to check if a given file exists or not. Following this answer I tried GetFileAttributesW. It works just fine for any ascii input, but it fails for ß, ü and á (and any other non-ascii character I suspect). I get ERROR_FILE_NOT_FOUND…
pulp_user
  • 2,454
  • 3
  • 14
  • 18
1
vote
0 answers

Can't get wchar_t* from wstring

I try to change value of wchar_t* variable with function call. I use pointers (Changing an array with a function in C?) and when assign char* to char* or wchar_t* to wchar_t* it works fine. But if I try to get wstring value and assign it to wchar_t*…
Denis Osipov
  • 91
  • 1
  • 6
1
vote
1 answer

Don't ignore whitespaces when using wscanf for UTF-8

I am trying to read wide charaters into an array of wchar_t from stdin. However, the negated scanset specifier ([^characters]) for ls does not work preperly as expected. The goal is that I want every whitespace read into str instead of being…
Kevin Dong
  • 5,001
  • 9
  • 29
  • 62
1
vote
1 answer

How to calculate the size needed for formated wchar array, `CRT_SECURE` way?

I need to calculate the size need for formated wchar array. Consider following code: wchar_t* Format(const wchar_t* format, ...) { va_list args; va_start(args, format); wchar_t *w = NULL; int len = _vsnwprintf(NULL, 0, format, args)…
NoName
  • 7,940
  • 13
  • 56
  • 108
1
vote
1 answer

How to convert a dynamic string to wchar_t to change background

I've been looking around the internet for some solutions however they all convert it from a constant string. Here's a piece of code I took to convert strings to wchar_t without additional libraries. What I'm trying to do is, I want to change the…
CraftedGaming
  • 499
  • 7
  • 21
1
vote
0 answers

wstring, wchar_t and fread()

I am loading text like this: wstring file; wchar_t *data = new wchar_t[file_size+1]; fread(data, sizeof(wchar_t), file_size+1, file_stream); file = data; // I want to create the wstring from the wchar_t data wcout << data.size() << " " << file; I…
1
vote
1 answer

How to safely and portably input and check for accent characters

What is the recommended way of reading some user input that can have special characters with e.g., accents, if it is not known in which locale it is input. How to safely compare a character of this user input if it is a special one, that I need to…
and roid
  • 11
  • 1
1
vote
0 answers

VS 2015 std::char_traits operations

At my workplace, we changed string type (which holds internationalized characters) for from std::wstring to std::u16string after VS 2015(Update 3) compiler upgrade. Due to this, we are seeing loads of performance regressions such as this. The…
Recker
  • 1,915
  • 25
  • 55
1
vote
1 answer

How to avoid integer promotion in C?

It is not clear how to write portable code in C, using wide-character API. Consider this example: #include #include #include int main(void) { setlocale(LC_CTYPE, "C.UTF-8"); wchar_t wc = L'ÿ'; if (iswlower(wc))…
Igor Liferenko
  • 1,499
  • 1
  • 13
  • 28
1
vote
1 answer

How to cast accented letters (wchar_t) to char?

I ported an application from Windows to Linux and I encountered a problem with character encoding: I saw that accented letters (e.g. 'é' 'à') are considered as wchar_t (4 bytes with g++) whereas under Visual Studio, they take 1 byte (char). My unit…
Aminos
  • 754
  • 1
  • 20
  • 40