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

How to work with wchar_t strings?

Possible Duplicate: In C++, Why can't I write to a string literal while I can write to a string object? I'm having my first experience with wchar_t strings and I'm having a lot of trouble. Each time I try to access a character in an wchar_t* the…
Petru Dimitriu
  • 365
  • 1
  • 5
  • 14
2
votes
3 answers

wprintf UTF16 (should be UTF8) on Linux?

1 It's really strange that wprintf show 'Ω' as 3A9 (UTF16), but wctomb convert wchar to CEA9 (UTF8), my locale is default en_US.utf8. As man-pages said, they should comform to my locale, but wpritnf use UTF16, why? excerpt from…
davy
  • 123
  • 1
  • 3
  • 8
2
votes
2 answers

wchar_t array passed into function

I am making a C program on windows using visual studio 2010. I am passing a wchar_t array to a function. //in main wchar_t bla[1024] = L"COM6"; mymethod(bla); static void mymethod(wchar_t *bla) { //do stuff } I used the debugger to watch bla,…
Michael
  • 5,994
  • 7
  • 44
  • 56
2
votes
1 answer

Convert vector to string c++

I'm trying to convert a vector to string (and then print it). std::string(vector_.begin(), vector_.end()); This code works fine, except äöü ÄÖÜ ß. They will be converted to: ��� I also tried converting to wstring and printing with wcout,…
Liam K.
  • 75
  • 7
2
votes
2 answers

Access Violation Error when using wcscat_s to concatenate two wchar_t*

I am trying to concatenate one wchar[] to a wchar_t* using wcscat_s function. I keep getting Access Violation Error. Here is the code HANDLE hFindDll = FindFirstFile(dllDir,&findDllData); wchar_t *path =…
andy
  • 484
  • 8
  • 21
2
votes
3 answers

How can I convert from ANSI character (char) to Unicode character (wchar_t) and vice versa?

How can I convert from ANSI character (char) to Unicode character (wchar_t) and vice versa? Is there any cross-platform source code for this purpose?
Amir Saniyan
  • 13,014
  • 20
  • 92
  • 137
2
votes
1 answer

C++: wchar_t cannot be stored in a std::map as a key or value

I am trying to make a variable with the data type std::map in C++. When I try this, Visual Studio gives this build error: C2440 'initializing': cannot convert from 'initializer list' to…
2
votes
1 answer

Using iconv while maintaining code correctness

I'm currently using iconv to convert documents with different encodings. The iconv() function has the following prototype: size_t iconv ( iconv_t cd, const char* * inbuf, size_t * inbytesleft, char* * outbuf, size_t * outbytesleft ); So…
ereOn
  • 53,676
  • 39
  • 161
  • 238
2
votes
2 answers

Why am I getting error code 87 (Invalid parameter) from RegisterClassEx?

Here's the code #include const wchar_t g_szClassName[] = L"myWindowClass"; // Step 4: the Window Procedure LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {/*...*/ return 0; } int WINAPI WinMain(HINSTANCE…
John
  • 6,433
  • 7
  • 47
  • 82
2
votes
1 answer

Printing Latin characters in Linux terminal using `std::wstring` and `std::wcout`

I'm coding in C++ on Linux (Ubuntu) and trying to print a string that contains some Latin characters. Trying to debug, I have something like the following: std::wstring foo = L"ÆØÅ"; std::wcout << foo; for(int i = 0; i < foo.length(); ++i) { …
George Hernando
  • 2,550
  • 7
  • 41
  • 61
2
votes
1 answer

Is wint_t always at least as large as wchar_t? And how can unsigned short satisfy reqirements of wint_t?

It seems everyone assumes wint_t is at least as large as wchar_t. However C standard allows wchar_t range to have value that do not directly correspond to any character in extended character set: The values WCHAR_MIN and WCHAR_MAX do not…
cryptain
  • 33
  • 5
2
votes
1 answer

to upper with char16_t array

Is there any way to do it nicely. When I try to use Boost's to_upper(), I get a std::bad_cast, so I ended with something like this: while(str[i]!=u'\0') { str[i]=(char16_t)to_upper((wchar_t)str[i]); i++; } I'm not even sure that this is…
NoSenseEtAl
  • 28,205
  • 28
  • 128
  • 277
2
votes
1 answer

Identifier wchar_t is undefined

I am trying to build an open-source project and I found that multiple of identifier wchar_t is undefined error I understand the definition for these intrinsic types comes from the compiler and I am getting for other types but not sure why it is…
Bhupesh Pant
  • 4,053
  • 5
  • 45
  • 70
2
votes
1 answer

Is it possible to use UTF-8 encoding by default in Visual Studio 2008?

Possible Duplicate: How to create a UTF-8 string literal in Visual C++ 2008 Is it possible to force Visual Studio to use UTF-8 encoding for all strings by default? For example have wchar_t *txt="hello"; encoded in utf8
Grim
  • 937
  • 10
  • 24
2
votes
3 answers

How can I convert a wchar_t* to char* without losing data?

I'm using a Japanese string as a wchar_t, and I need to convert it to a char*. Is there any method or function to convert wchar_t* to char* without losing data?
Greenhorn
  • 658
  • 2
  • 8
  • 24