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
4
votes
2 answers

Is it possible to get a pointer to String^'s internal array in C++/CLI?

The goal is to avoid copying the string data when I need a const wchar_t*. The answer seems to be yes, but the function PtrToStringChars doesn't have its own MSDN entry (it's only mentioned in the KB and blogs as a trick). That made me suspicious…
CannibalSmith
  • 4,742
  • 10
  • 44
  • 52
4
votes
2 answers

Equivalent of wstring in C

How can I read and access Unicode characters with standard C. Previously I was using C++ and std::wstring for whole word and 'const wchar_t' for a single characters, which works perfectly( below is example code). But now I am not allowed to use C++.…
MMH
  • 1,676
  • 5
  • 26
  • 43
4
votes
2 answers

Why `strchr` seems to work with multibyte characters, despite man page disclaimer?

From: man strchr char *strchr(const char *s, int c); The strchr() function returns a pointer to the first occurrence of the character c in the string s. Here "character" means "byte"; these functions do not work with wide or multibyte…
n0p
  • 3,399
  • 2
  • 29
  • 50
4
votes
2 answers

C++: Is there any good way to read/write without specifically stating character type in function names? (cout vs wcout, etc)

I'm having a problem getting a program to read from a file based on a template, for example: bool parse(basic_ifstream &file) { T ch; locale loc = file.getloc(); basic_string buf; file.unsetf(ios_base::skipws); if…
Mark L.
  • 41
  • 1
4
votes
4 answers

How to convert (not necessarily programmatically) between Windows' wchar_t and GCC/Linux one?

Suppose I have this Windows wchar_t string: L"\x4f60\x597d" and L"\x00e4\x00a0\x597d" and would like to convert it (not necessarily programmatically; it will be a one-time thing) to GCC/Linux wchar_t format, which is UTF-32 AFAIK. How do I do it?…
Paweł Hajdan
  • 18,074
  • 9
  • 49
  • 65
4
votes
4 answers

Cast (const) char * to LPCWSTR

I'm trying to use FindWindow() from WinAPI, and I want to ask an input for window's title from the user: char *input; cout << "Window title: "; cin >> input; Pretty standard. Now then, how do I convert this to LPCWSTR for FindWindow()? I've already…
Markus Meskanen
  • 19,939
  • 18
  • 80
  • 119
4
votes
2 answers

Wide exec for C/C++

Is there a wchar_t version of exec[lv][pe] (i.e. an exec that uses wchar_t as path and wchar_t as arguments)? In Windows, I can just do CreateProcessW(process, cmdline), but in *nix, I'm stuck (i.e. no pure POSIX equivalent). I'm trying to add…
Andrey Vul
4
votes
3 answers

Using wsprintf to convert int to wchar_t*

I'm trying to get a wchar_t* formatted with an int as a parameter. I've Googled a lot but I've only ended up more confused. So, consider this code: int main(int argc, char** argv) { wchar_t buf[16]; wsprintf(buf, L"%d", 5); …
Theodoros Chatzigiannakis
  • 28,773
  • 8
  • 68
  • 104
4
votes
1 answer

Is there a wchar_t version of getcwd?

I am trying to this: wchar_t buff[PATH_MAX]; wgetcwd( buff, PATH_MAX); I have also tried _wgetcwd. Google suggests _wgetcwd is in dir.h, but i have never heard of such a header file. I'm using GCC 4.3. Thank you.
mikbal
  • 1,168
  • 1
  • 16
  • 27
4
votes
1 answer

Clang error, no viable conversion

I am facing an issue with clang 3.1. This particular issue does not arise with GCC 4.2. The following is an example of the error that occurs: #include #include #include #include typedef unsigned short…
joydsouza
  • 43
  • 3
4
votes
4 answers

static_cast wchar_t* to int* or short* - why is it illegal?

In both Microsoft VC2005 and g++ compilers, the following results in an error: On win32 VC2005: sizeof(wchar_t) is 2 wchar_t *foo = 0; static_cast(foo); Results in error C2440: 'static_cast' : cannot convert from 'wchar_t *' to…
VoidPointer
  • 17,651
  • 15
  • 54
  • 58
3
votes
3 answers

How do I convert from a wchar_t* to a wstring?

Or how to I initialize a wstring using a wchar_t*? I tried something like this, but it's not quite working. I'm given an LPVOID and it points to a wchar_t pointer. I just want to get it into a wstring so I can use some normal string functions on…
ScArcher2
  • 85,501
  • 44
  • 121
  • 160
3
votes
3 answers

How to concat an int to a wchar_t* in C++?

I have to create and write on N files, everyone must have an integer ending to identificate it. This is my piece of code: for(int i=0; i
DavideChicco.it
  • 3,318
  • 13
  • 56
  • 84
3
votes
1 answer

Effect of default argument promotions on wchar_t

I am a bit confused about how default argument promotions effect wchar_t. I understand that char is promoted to int, and therefore I have to supply int as the second parameter of va_arg, otherwise I may (GCC) or may not (MSVC) get an error, as…
z32a7ul
  • 3,695
  • 3
  • 21
  • 45
3
votes
1 answer

What does the minus in /Zc:wchar_t- mean?

Recently I had some linking issues caused by the presence (or absence) of this flag. /Zc:wchar_t- I've read the docs, but they don't mention the trailing minus. But every discussion of it seems to include it. What does it mean?
i_am_jorf
  • 53,608
  • 15
  • 131
  • 222