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

Cannot convert ‘char**’ to ‘wchar_t**’

The code excerpt: int main(int argc, char *argv[]){ PySys_SetArgv(argc, argv); produces error message error: cannot convert ‘char**’ to ‘wchar_t**’ for argument ‘2’ to ‘void PySys_SetArgv(int, wchar_t**)’ How do I convert argv?
user1561108
  • 2,666
  • 9
  • 44
  • 69
3
votes
1 answer

swprintf chokes on characters outside 8-bit range

This happens on OS X, though I suspect it applies to any UNIX-y OS. I have two strings that look like this: const wchar_t *test1 = (const wchar_t *)"\x44\x00\x00\x00\x73\x00\x00\x00\x00\x00\x00\x00"; const wchar_t *test2 = (const wchar_t…
mhenry1384
  • 7,538
  • 5
  • 55
  • 74
3
votes
1 answer

Printing a wchar_t gives weird output

Running this code snippet: wchar_t *wstr = L"áßå®"; wprintf(L"%s",wstr); gives the output: « instead of áßå® I am new to wchar_t. How do I get the expected output?
Mutai Mwiti
  • 487
  • 1
  • 7
  • 20
3
votes
4 answers

Index a character in a wchar_t array

The thread "Size of wchar_t* for surrogate pair" shows, that the size of memory required to save a wchar_t value may differ as it can take more space to encode some characters (surrogate pair). That leads me to the following question: How do I then…
Sam
  • 1,301
  • 1
  • 17
  • 26
3
votes
2 answers

How do I convert wchar_t* to string?

I am new to C++. And I am trying to convert wchar_t* to string. I cannot use wstring in condition. I have code below: wchar_t *wide = L"中文"; wstring ret = wstring( wide ); string str2( ret.begin(), ret.end() ); But str2 returns some strange…
Joshua Son
  • 1,839
  • 6
  • 31
  • 51
3
votes
1 answer

How to make wchar_t 16 bit with clang for linux-x64?

I cannot make clang on 64 bit linux to compile wchar_t to 16 bit printf("%i ", sizeof (wchar_t)); prints 4 clang++ -fshort-char test.cpp although I use -fshort-char my question is how to make wchar_t to 16 bit. is #define the only option? #define…
exebook
  • 32,014
  • 33
  • 141
  • 226
3
votes
5 answers

.c_str() weirdness? Data changes without rhyme or reason?

I have this simple function: const wchar_t *StringManager::GetWCharTStar(int stringId) { std::wstring originalString = StringManager::GetString(stringId); const wchar_t *retStr = originalString.c_str(); return retStr; } At the second…
user189320
3
votes
2 answers

How convert const wchar_t* from C DLL to C# string automatically

It is just a curiosity. Perhaps there is a person in this world who did such things: I have to export C function and load it from C# code via DllImport const wchar_t * SysGetLibInfo() { return dllmanager.SysGetLibInfo(); } The best things to do…
Mnt DXM
  • 168
  • 1
  • 7
3
votes
3 answers

Are wchar_t and multibyte functions part of ANSI C?

C99 and C11 support wchar_t and multibyte functions .But I am not sure about ANSI C (1989). Is it correct that wchar_t and multibyte functions (mblen, mbstowcs, mbtowc, wcstombs, wctomb) are part of ANSI C? I don't find these functions in Kernighan…
Amir Saniyan
  • 13,014
  • 20
  • 92
  • 137
3
votes
4 answers

Conver QString to BSTR and vice versa

I want to convert QString to BSTR and vice versa. This is what i try to convert QString to BSTR : std::wstring str_ = QString("some texts").toStdWString(); BSTR bstr_ = str_.c_str(); and to convert BSTR to QString : BSTR bstr_; wchar_t *str_ =…
Hesam Qodsi
  • 1,569
  • 3
  • 25
  • 38
3
votes
3 answers

How to declarate a vector of wchar_t[] in C++?

I need to use in C++ programm vectors containing c-string of wchar_t. I tried to make it so: using std::vector; vector string_list(100); But I get large error output containing the following words: error: functional cast to array…
shau-kote
  • 1,110
  • 3
  • 12
  • 24
3
votes
3 answers

Assigning non-ASCII characters to wide char and printing with printf

How can I assign non-ASCII characters to a wide char and print it to the console? This code down doesn't work: #include int main(void) { wchar_t wc = L'ć'; printf("%lc\n", wc); printf("%ld\n", wc); return…
balky
  • 371
  • 4
  • 11
3
votes
1 answer

Cannot convert char[33] to LPCTSTR or if I typecast to LPCTSTR desired results not getting

I am trying to use listbox.Addstring(); in MFC application which will take LPCTSTR. I am passing a variable of char array that's 33 chars long. ListBox.AddString(Adapter_List->pScanList->network[0].szSsid); SzSsid is declared as char szSsid[33]; I…
david
  • 413
  • 5
  • 20
3
votes
2 answers

C++ wchar_t error undefined

I'm new to c++. I know wchar_t is wide character. What is wrong in the following code ?? Did i not include the appropriate library ?? #include #include void main() { wchar_t *s=L"Hello, World"; cout<
Ajay
  • 61
  • 3
  • 13
3
votes
2 answers

Visual C++, wchar_t* command-line arguments cannot be compared?

I am having a little bit of trouble trying to implement a certain assignment based on which string argv[1] equals. int _tmain(int argc, _TCHAR* argv[]) //wchar_t { if (argc != 2) exit(1); if (argv[1] == L"-foo") …
Byzantian
  • 3,208
  • 4
  • 27
  • 31