wchar.h is a header file in the C standard library. It is a part of the extension to the C programming language standard done in 1995. It contains extended multibyte and wide character utilities. The standard header
Questions tagged [wchar]
196 questions
2
votes
0 answers
I am trying to run my first c++ program and am getting this error:
c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\cwchar:44:10: fatal error: wchar.h: No such file or directory #include

m dib
- 21
- 1
2
votes
3 answers
Is WCHAR in COM interfaces a good thing?
Is WCHAR in COM interfaces a good thing ?
I've been searching the internet for an answer to this question with no results.
Basically should char* / wchar* be used in COM or should i use BSTR instead ?
Is it safe or does it depend ?
In this code…

Carl Serl
- 51
- 6
2
votes
1 answer
Error: argument of type "const wchar_t *" is incompatible with parameter of type "WCHAR *"
I have a below code for WinHTTPRequest:
DWORD WinHTTPRequest(LPCTSTR pServerName, LPCTSTR pRequest, WCHAR* sCommand, LPVOID pPostData, int nPostDataLength, LPCWSTR pwszHeaders, char **dataOut, int *nRead, WCHAR **dataHeaderOut, BOOL bTestProxy, BOOL…

S Andrew
- 5,592
- 27
- 115
- 237
2
votes
1 answer
How to count the number of multibyte characters?
I'd like to get 5 instead of 10 for the following program. Does anybody know how to fix the code to count the number of multibyte characters? Thanks.
/* vim: set noexpandtab tabstop=2 shiftwidth=2 softtabstop=-1 fileencoding=utf-8: */
#include…

user1424739
- 11,937
- 17
- 63
- 152
2
votes
1 answer
Can't read and echo back unicode input in C
I wrote the following code:
#include
#include
int main() {
wchar_t wc[80];
wscanf(L"%ls", &wc);
wprintf(L"%ls", wc);
return 0;
}
My terminal supports Unicode, compiled using gcc 8.2.1 on Linux.

i cant
- 401
- 2
- 9
2
votes
3 answers
array of wchar_t
I would like to have an array of wchar_t's.
The following works:
char** stringArray;
int maxWords = 3;
stringArray = new char*[maxWords];
stringArray[0] = "I";
stringArray[1] = " Love ";
stringArray[2] = "C++"
but this does not
wchar_t **…

Nemesis
- 109
- 1
- 1
- 8
2
votes
3 answers
Why is the following C++ code printing only the first character?
I am trying to convert a char string to a wchar string.
In more detail: I am trying to convert a char[] to a wchar[] first and then append " 1" to that string and the print it.
char src[256] = "c:\\user";
wchar_t temp_src[256];
mbtowc(temp_src,…
user529141
2
votes
3 answers
Compare C-string of types char* and wchar_t*
I have a key like:
wchar_t key[] = L"764frtfg88fgt320nolmo098vfr";
and a char* row[i] returned by a query from a Database.
I'd like to compare my Key with row[i]. I tried with
wcscmp (key,row[i]) != 0)
but it gives me an error. Any suggestions ?

A.Adil
- 29
- 1
- 6
2
votes
2 answers
One function for handling char* and wchar_t*
Right now I have two functions which do the exact same parsing stuff, one for char* and one for wchar_t*. I'd like to have just one function so that I only need to change it once (for consistency). Converting the whole string to char* or wchar_t* is…

MrTux
- 32,350
- 30
- 109
- 146
2
votes
3 answers
MFC - How to convert WCHAR to CString?
Is it possible to convert WCHAR to CString? I need to do that, or even convert it to char or char*.
Thanks!

amiltonjr
- 323
- 1
- 3
- 9
2
votes
1 answer
How to convert a string containting the hex value of a UTF-8 to a wchar in C?
I am using GCC. I have a string containing the hex value of a UTF-8 char like this:
char[] str = "4e86"
(such kind of strings are read out from an xml-file).
I would like this to convert this to a wchar containing the character \u4e86.
I know I can…

ndbd
- 2,417
- 3
- 23
- 32
2
votes
3 answers
Convert 16 bits in memory into std::string
I'm getting 16 bits from a struct in memory, and I need to convert them into a string. The 16 bits represent a unicode char:
typedef struct my_struct {
unsigned unicode : 16;
} my_struct;
I started by casting the bits into an unsigned…

mirandak
- 185
- 1
- 1
- 7
2
votes
1 answer
LPWSTR, wchar_t* and unsigned short pointer in C++
I'm trying to understand if these types are all the same. I have this function from windows.h: GetCommandLine(), in UNICODE mode, and it returns a LPWSTR. Now, if I dig deeper I can see how LPWSTR is wchar_t* and if I go even further, I find out…

ali
- 10,927
- 20
- 89
- 138
2
votes
1 answer
Why does wprintf separate Unicode ligature into two different graphemes?
Code:
#include
#include
#define USE_W
int main()
{
#ifdef USE_W
const wchar_t *ae_utf16 = L"\x00E6 & ASCII text ae\n";
wprintf(ae_utf16);
#else
const char *ae_utf8 = "\xC3\xA6 & ASCII text ae\n";
…

user206334
- 850
- 1
- 8
- 18
2
votes
4 answers
What is the proper way to convert an int to wchar_t?
Say you have "methods"
int Read(...)
{
unsigned char Byte = 0;
if(!ReadFile(.., &byte, 1,...))
return -1;
return Byte;
}
int ReadBlock(LPWSTR buffer, int cchBuffer ...)
{
int c = 0;
int cnt = 0;
do
{
…

CS.
- 1,845
- 1
- 19
- 38