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
3
votes
5 answers

Unexpected output of std::wcout << L"élève"; in Windows Shell

While testing some functions to convert strings between wchar_t and utf8 I met the following weird result with Visual C++ express 2008 std::wcout << L"élève" << std::endl; prints out "ÚlÞve:" which is obviously not what is expected. This is…
chmike
  • 20,922
  • 21
  • 83
  • 106
3
votes
0 answers

Is there a way to store and retrieve wide chars, wchar_t in sqlite using c++?

I am trying to store wstrings in sqlite. Does sqlite support the storage of wstrings? Below is code snippet Person Table created using CREATE TABLE Persons ( PersonID int, LastName varchar(255),FirstName varchar(255)); int callback(void*…
Vihari Vs
  • 31
  • 2
3
votes
1 answer

determine whether wchar_t is a built-in type or alias

Yes, wchar_t is supposed to be a built-in type in C++; unfortunately, that's not the case with some (very) old compilers. Is there a (compiler-specific, e.g., GCC/g++) way to determine whether wchar_t is a built-in type (keyword) or a typedef? The…
Ðаn
  • 10,934
  • 11
  • 59
  • 95
3
votes
3 answers

Trying to understand C++ pointers and data type initializations

I am trying to learn C++, I have a fair bit of experience in C# and the 2 languages are so dissimilar and I am having trouble understanding data types and pointer variants of data types and the initialization of them, please consider the code…
3
votes
1 answer

Convert wchar_t to string?

I have a wchar_t I'd like to convert to a string. The string should then be read using stringstream. I have looked converting it over here: http://msdn.microsoft.com/en-us/library/ms235631(v=vs.80).aspx but none of them return anything useable with…
Stuvolas
  • 31
  • 1
  • 1
  • 2
3
votes
2 answers

How can I check if a template type parameter is a character type or a string type?

I am trying to write code that will be able to distinguish between character types (char, wchar_t, etc.), string types (std::string, std::wstring, etc.), and numeric types, so I can enclose characters in single-quotes and strings in double-quotes.…
SGeorgiades
  • 1,771
  • 1
  • 11
  • 11
3
votes
2 answers

Error reading characters of string after wcscpy_s

I have a problem with the wcscpy_s function. After wcscpy_s returns the parameter (stringOneand stringTwo) of my function are not readable. Here is simple demo to show the problem. void testFunc(LPCWSTR stringOne, LPCWSTR stringTwo) { wchar_t*…
Kevin
  • 785
  • 2
  • 10
  • 32
3
votes
1 answer

wchar_t* with UTF8 chars in MSVC

I am trying to format wchar_t* with UTF-8 characters using vsnprintf and then printing the buffer using printf. Given the following code: /* This code is modified version of KB sample: …
vulcan raven
  • 32,612
  • 11
  • 57
  • 93
3
votes
2 answers

wchar_t is 2-bytes in visual studio and stores UTF-16. How do Unicode-aware applications work with characters above U+FFFF?

We are at our company planning to make our application Unicode-aware, and we are analyzing what problems we are going to encounter. Particularly, our application will for example rely heavily on lengths of strings and we would like to use wchar_t as…
Benoit
  • 76,634
  • 23
  • 210
  • 236
3
votes
0 answers

May wchar_t be promoted to wint_t?

I see one contradiction of glibc reference and Amendment 1 to C90. The quote from glibc reference says that wchar_t may be promoted to wint_t: if wchar_t is defined as char the type wint_t must be defined as int due to the parameter promotion But…
Igor Liferenko
  • 1,499
  • 1
  • 13
  • 28
3
votes
1 answer

Why functions from wctype.h do not work without setlocale()?

My setup: glibc 2.24, gcc 6.2.0, UTF-8 environment. Consider the following example: #include #include #include int main(void) { setlocale(LC_CTYPE, "en_US.UTF-8"); wchar_t wc = L'я'; /* 00000100 01001111 */ if…
Igor Liferenko
  • 1,499
  • 1
  • 13
  • 28
3
votes
2 answers

Why perror() changes orientation of stream when it is redirected?

The standard says that: The perror() function shall not change the orientation of the standard error stream. This is the implementation of perror() in GNU libc. Following are the tests when stderr is wide-oriented, multibyte-oriented and not…
Igor Liferenko
  • 1,499
  • 1
  • 13
  • 28
3
votes
3 answers

c++ write non english text to a file

I saw dozens of questions about this topic but none of them helped me. Suppose I have a string "հայեր" or "русский" (wchat_t*, wstring, LPTSTR, or something else). Now I want to create an output file "res.txt" and write the string down. While trying…
mbaros
  • 825
  • 8
  • 31
3
votes
1 answer

How to work with UTF-16 in python ctypes?

I have a foreign C library which uses utf-16 in API: as function arguments, return values and structure members. On Windows its OK with ctypes.c_wchar_p, but under OSX ctypes uses UCS-32 in c_wchar and I could not find the way to support…
emett
  • 128
  • 13
3
votes
2 answers

Determine if a string is a valid wchar_t* in C

I'm trying to recode a part of printf. setlocale(LC_ALL, "en_US.UTF-8"); int ret = printf("%S\n", "我是一只猫。"); printf("Printf returned %d\n", ret); If the format is %s, printf writes the wide characters and returns 19. If the format is %S, printf…
Bilow
  • 2,194
  • 1
  • 19
  • 34