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

warning: multi-character character constant [-Wmultichar]

I want to have an Array of the Greek alphabet and this is what I do: wchar_t pcletters[30] = {'α' , 'ά' , 'β' , 'γ' , 'δ' , 'ε' , 'ζ' , 'η', 'θ' , 'ι' , 'κ' , 'λ' , 'μ' , 'ν','ξ' , 'ο' , 'π' , 'ρ' , 'σ' , 'τ' , 'υ' , 'φ' , 'χ' , 'ψ' , 'ω', 'έ' ,…
billpcs
  • 633
  • 10
  • 17
7
votes
3 answers

How to convert concatenated strings to wide-char with the C preprocessor?

I am working on a project where I have many constant strings formed by concatenation (numbers, etc.). For example, I have a LOCATION macro that formats __FILE__ and __LINE__ into a string that I can use to know where I am in the code, when printing…
7
votes
4 answers

Outputting unicode characters in windows terminal

Over the past week I've been working on a roguelike game in C++ along with a friend. Mostly too learn the language. I'm using: pdcurses Windows 7 Visual studio C++ To output wchar_t's wherever I want to in the console. I have succeeded in…
Martin Nycander
  • 1,309
  • 13
  • 29
6
votes
5 answers

Convert wchar_t* to UTF-16 string

I need a code in C++ to convert a string given in wchar_t* to a UTF-16 string. It must work both on Windows and Linux. I've looked through a lot of web-pages during the search, but the subject still is not clear to me. As I understand I need…
Andrei Baskakov
  • 161
  • 2
  • 3
6
votes
5 answers

How do you efficiently copy BSTR to wchar_t[]?

I have a BSTR object that I would like to convert to copy to a wchar__t object. The tricky thing is the length of the BSTR object could be anywhere from a few kilobytes to a few hundred kilobytes. Is there an efficient way of copying the data…
Obediah Stane
6
votes
1 answer

QChar to wchar_t

I need to convert a QChar to a wchar_t I've tried the following: #include #include #include using namespace std; int main(int argc, char** argv) { QString mystring = "Hello World\n"; wchar_t…
Zac
  • 2,229
  • 9
  • 33
  • 41
6
votes
2 answers

Converting a UTF-8 text to wchar_t

I know this question has been asked quite a few times here, and i did read some of the answers, But there are a few suggested solutions and im trying to figure out the best of them. I'm writing a C99 app that basically receives XML text encoded in…
Yarel
  • 424
  • 1
  • 6
  • 15
6
votes
3 answers

How do i convert const wchar_t* to System::String?

I need to convert my SHA1 (wchar_t*) to a normal String^ in order to use it in a certain function. Any ideas? I tried Google but all the results were the exact opposite of my question. :\ NOTE: I am using C++.NET framework and Windows Forms…
FreelanceCoder
  • 596
  • 2
  • 8
  • 12
6
votes
3 answers

wchar_t and encoding

If I want to convert a piece of string to UTF-16, say char * xmlbuffer, do I have to convert the type to wchar_t * before encoding to UTF-16? And is char* type reqired before encoding to UTF-8? How is wchar_t, char related to UTF-8 or UTF-16 or…
Hunter
  • 151
  • 1
  • 14
5
votes
1 answer

What's the difference between glib gunichar and wchar_t and which is better for cross-platform solutions?

I'm trying to write some C code which is portable only so far as the user has gcc, and has glib installed. From all my research, I've found that with gcc, a wchar_t is always defined as 4 bytes, and with glib a gunichar is also 4 bytes. What I…
ckot
  • 819
  • 2
  • 10
  • 23
5
votes
2 answers

boost::format and wchar_t

I am trying to format a string using boost: wchar_t *msg; // fill msg boost::format("Error: %s") % msg).str() What I get instead of msg's content, is the address of msg in hex. No success with things like these: boost::format("Error: %s") % new…
el_shayan
  • 2,735
  • 4
  • 28
  • 42
5
votes
2 answers

Opening a Unicode file in pure C

I am trying to open a .txt file that is wholly Chinese. Can I use normal fopen/fclose procedures to it even though the stream would be 100% Unicode or are there any exlusive tools for handling wide characters? I'd be grateful for precise answers, I…
yauser
  • 707
  • 2
  • 8
  • 19
5
votes
3 answers

Solution for missing std::wstring support in Android NDK?

I have a game which uses std::wstring as its basic string type in thousand of places as well as doing operations with wchar_t and its functions: wcsicmp() wcslen() vsprintf(), etc. The problem is wstring is not supported in R5c (latest ndk at the…
user548569
  • 158
  • 2
  • 6
5
votes
1 answer

Conditional jump or move depends on uninitialised value(s) for std::wistringstream

I have stolen the following code snippet from cppreference.com and adopted it for usage of wchar_t: #include #include #include template struct test_seq {}; template <> struct test_seq { …
avitase
  • 134
  • 1
  • 8
5
votes
4 answers

How do I read Unicode-16 strings from a file using POSIX methods in Linux?

I have a file containing UNICODE-16 strings that I would like to read into a Linux program. The strings were written raw from Windows' internal WCHAR format. (Does Windows always use UTF-16? e.g. in Japanese versions) I believe that I can read them…
Harvey
  • 5,703
  • 1
  • 32
  • 41