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
93
votes
8 answers

How I can print the wchar_t values to console?

Example: #include using namespace std; int main() { wchar_t en[] = L"Hello"; wchar_t ru[] = L"Привет"; //Russian language cout << ru << endl << en; return 0; } This code only prints HEX-values like…
zed91
  • 1,073
  • 1
  • 8
  • 10
89
votes
12 answers

Is TCHAR still relevant?

I'm new to Windows programming and after reading the Petzold book I wonder: is it still good practice to use the TCHAR type and the _T() function to declare strings or should I just use the wchar_t and L"" strings in new code? I will target only…
Fábio
  • 3,291
  • 5
  • 36
  • 49
82
votes
10 answers

How to print Unicode character in C++

I am trying to print a Russian "ф" (U+0444 CYRILLIC SMALL LETTER EF) character, which is given a code of decimal 1092. Using C++, how can I print out this character? I would have thought something along the lines of the following would work,…
James Raitsev
  • 92,517
  • 154
  • 335
  • 470
69
votes
4 answers

WChars, Encodings, Standards and Portability

The following may not qualify as a SO question; if it is out of bounds, please feel free to tell me to go away. The question here is basically, "Do I understand the C standard correctly and is this the right way to go about things?" I would like to…
Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084
69
votes
5 answers

I want to convert std::string into a const wchar_t *

Is there any method? My computer is AMD64. ::std::string str; BOOL loadU(const wchar_t* lpszPathName, int flag = 0); When I used: loadU(&str); the VS2005 compiler says: Error 7 error C2664:: cannot convert parameter 1 from 'std::string *__w64 '…
user25749
  • 4,825
  • 14
  • 61
  • 83
43
votes
2 answers

get length of `wchar_t*` in c++

Please, how can I find out the length of a variable of type wchar_t* in c++? code example below: wchar_t* dimObjPrefix = L"retro_"; I would like to find out how many characters dimObjPrefix contains
Jacob
  • 1,242
  • 2
  • 9
  • 14
38
votes
7 answers

How do I convert wchar_t* to std::string?

I changed my class to use std::string (based on the answer I got here but a function I have returns wchar_t *. How do I convert it to std::string? I tried this: std::string test = args.OptionArg(); but it says error C2440: 'initializing' : cannot…
codefrog
  • 611
  • 3
  • 10
  • 13
36
votes
2 answers

Conversion of wchar_t* to string

How can I convert an wchar_t* array to an std::string varStr in win32 console.
AnasShoaib90
  • 629
  • 2
  • 7
  • 14
21
votes
1 answer

Understanding and writing wchar_t in C

I'm currently rewriting (a part of) the printf() function for a school project. Overall, we were required to reproduce the behaviour of the function with several flags, conversions, length modifiers ... The only thing I have left to do and that gets…
kRYOoX
  • 397
  • 2
  • 3
  • 10
20
votes
6 answers

Is wchar_t just a typedef of unsigned short?

for example, does: wchar_t x; translate to: unsigned short x;
Marlon
  • 19,924
  • 12
  • 70
  • 101
19
votes
4 answers

Why isn't wchar_t widely used in code for Linux / related platforms?

This intrigues me, so I'm going to ask - for what reason is wchar_t not used so widely on Linux/Linux-like systems as it is on Windows? Specifically, the Windows API uses wchar_t internally whereas I believe Linux does not and this is reflected in a…
user257111
19
votes
2 answers

Outputting 'wchar_t*' to an 'ofstream'

I want to output a text to a file via two pointers that I have declared: wchar_t *Col1="dsffsd", *Col2="sdfsf"; Here is what I have tried: std::ofstream fout; fout.open(NativeDatabasePathHist); fout<<"testing"; fout<<" "<
Aan
  • 12,247
  • 36
  • 89
  • 150
18
votes
4 answers

UTF-8 Compatibility in C++

I am writing a program that needs to be able to work with text in all languages. My understanding is that UTF-8 will do the job, but I am experiencing a few problems with it. Am I right to say that UTF-8 can be stored in a simple char in C++? If so,…
Qman
  • 377
  • 1
  • 4
  • 14
17
votes
1 answer

Relationship between 'x' and L'x' and widen('x')

Let x be any member of the basic source character set. 'x' and L'x' are members of the basic execution character set and the basic execution wide-character set, respectively. Is it true that integral values of 'x' and L'x' must be equal? It looks…
n. m. could be an AI
  • 112,515
  • 14
  • 128
  • 243
16
votes
4 answers

Cross-platform strings (and Unicode) in C++

So I've finally gotten back to my main task - porting a rather large C++ project from Windows to the Mac. Straight away I've been hit by the problem where wchar_t is 16-bits on Windows but 32-bits on the Mac. This is a problem because all of the…
user438380
  • 193
  • 1
  • 6
1
2 3
31 32