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

Why do I need to put an L before the string and do I create this variable correctly?

I am sort of new to C++ and I got troubles understanding the usage of the data types fully. I have these variables to be applied to createwindow parameters and the class with it. That takes an LPCWSTR data type. LPCWSTR szTitle = L"Hello"; LPCWSTR…
JohnSilver
  • 83
  • 1
  • 3
  • 10
5
votes
2 answers

Writing Unicode Characters to an OStream

I'm working with unicode/wide characters and I'm trying to create a toString method (Java ::toString equiv). Will ostream handle wide characters, if so is there a way to warn the consumer of the stream that it is unicode coming out of it?
monksy
  • 14,156
  • 17
  • 75
  • 124
5
votes
4 answers

How to convert wchar_t** to char**?

I get argv as wchar_t** (see below), because I need to work with unicode, but I need to convert it to char **. How can I do that? int wmain(int argc, wchar_t** argv) {
Narek
  • 38,779
  • 79
  • 233
  • 389
5
votes
2 answers

What is the fastest method to get "const wchar_t*" from QString

I want to pass a QString variable to a function with const wchar_t* argument. Safe solution is: void foo(const wchar_t*); QString x = "test"; foo(x.toStdWString().c_str()); but it has overhead of converting to wstring. Is there any faster…
A.Danesh
  • 844
  • 11
  • 40
5
votes
1 answer

wcout function does not print a french character

I am using the wcin in order to store a single character in a wchar_t. Then I try to print it with a wcout call and the french character 'é' : but I can't see it at my console. My compiler is g++ 4.5.4 and my OS is Ubuntu 12.10 64 bits. Here is my…
loloof64
  • 5,252
  • 12
  • 41
  • 78
5
votes
2 answers

Is wchar_t guaranteed to be distinct from any integer type?

On my system, wchar_t and int are distinct types with the same properties: #include sizeof(wchar_t) == sizeof(int) == 4 std::is_signed == std::is_signed == std::true_type std::is_same == std::false_type In…
addaon
  • 1,097
  • 9
  • 25
5
votes
4 answers

wchar_t for UTF-16 on Linux?

Does it make any sense to store UTF-16 encoded text using wchar_t* on Linux? The obvious problem is that wchar_t is four bytes on Linux and UTF-16 takes usually two (or sometimes two groups of two) bytes per character. I'm trying to use a…
user708549
5
votes
1 answer

SimpleJSON C++ Class cannot parse strings on Android (NDK) yet same class works on every other platform

I've successfully ported my game to Cocos2d-x and it runs great on Linux, QNX, iOS and Mac. I've also setup the Android NDK and am able to successfully build and run the App on Android (all from the exact same sources, which is really neat !) On…
5
votes
3 answers

Any downsides using '?' instead of L'?' with wchar_t?

Are there any downsides to using '?'-style character literals to compare against, or assign to, values known to be of type wchar_t, instead of using L'?'-style literals?
user541686
  • 205,094
  • 128
  • 528
  • 886
4
votes
1 answer

std::from_chars overload for wchar_t?

Is there any reason why std::from_chars doesn't have an overload for wchar_t? Currently, there are only four overloads one of them being: constexpr std::from_chars_result from_chars( const char* first, const char* last, …
digito_evo
  • 3,216
  • 2
  • 14
  • 42
4
votes
3 answers

How to convert argv to wide chars in Win32 command line application?

I'm using the win32 api for C in my program to read from a serial port, it seems to be pretty low level stuff. Assuming that there is no better way of reading from a serial port, the CreateFile function involves a LPCWSTR argument, I've read and it…
Michael
  • 5,994
  • 7
  • 44
  • 56
4
votes
1 answer

Probably defect in wording of C++ working draft (integer conversion rank rules)

I have found a possible contradiction in the working draft of standard C++. First I present the facts, and my question comes at the end. When the integer conversion ranks are established, [conv.rank]/1.1 says No two signed integer types [...]…
pablo1977
  • 4,281
  • 1
  • 15
  • 41
4
votes
2 answers

Win32: Determine whether stdout handle is char or wchar stream

I'm writing a win32 utility function for our product that needs to call an arbitrary program via the shell and log its output. We do this by redirecting the stdout from the child process into a pipe: saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);…
JSBձոգչ
  • 40,684
  • 18
  • 101
  • 169
4
votes
1 answer

Is long string literal's type long int*?

According to the answers in this question, a literal like L"test" has type wchar_t[5]. But the following code with GCC seems to say something different: int main() { struct Test{char x;} s; s="Test"; // ok, char* as expected s=L"Test";…
Ruslan
  • 18,162
  • 8
  • 67
  • 136
4
votes
0 answers

Could C++ cout correctly output multi-byte string?

I've got a program like below: #include using namespace std; int main() { wcout << "abc" << endl; cout << "你好" << endl; cout << L"abc" << endl; return 0; } My questions: The first "wcout" has no problem, my question is:…
Hind Forsum
  • 9,717
  • 13
  • 63
  • 119