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
1
vote
2 answers

How to copy/convert a char string to a wchar_t string in C?

I looked around, and found a program where swprintf is used from the library. However i tried that method, and it didn't work. It just says program.exe has stopped working when i run the program. I copied the sample program i found, into…
Rizvan Ferdous
  • 69
  • 1
  • 2
  • 12
1
vote
1 answer

C++: Comparing strings or wstrings with special characters in them (á, é, ő, etc.)

I recently got an assignment that requires me to compare words. I don't want to describe it in full, but I have to compare the words character-by-character to see how similar two words are. Now the problem is that the input text I have to use…
akrammon
  • 11
  • 1
  • 4
1
vote
1 answer

Function logic reuse between char string and wchar_t string without explicit string copying?

I'm writing a data structure in C to store commands; Here is the source pared down to what I'm unsatisfied with: #include #include #include #include #include "dbg.h" #include "commandtree.h" struct…
Aioi Yuuko
  • 118
  • 7
1
vote
2 answers

C store and print wchar_t

I want to store a string with characters from extend ascii table, and print them. I tried: wchar_t wp[] = L"Росси́йская Акаде́мия Нау́к "; printf("%S", wp); I can compile but when I run it, nothing is actually displayed in my terminal. Could you…
edelangh
  • 311
  • 1
  • 12
1
vote
1 answer

Why are wchar_t / unsigned short now distinct, but there is no analogous char / unsigned byte distinction?

It just seems like "not of one mind" in the design here, because integer data and character data of 16 bits is now differentiable but integer and character data of 8 bits is not. C++ has always had the only choice for 8-bit values a 'char'. But the…
VoidStar
  • 5,241
  • 1
  • 31
  • 45
1
vote
2 answers

utf8 and utf16 conversion

I have a wchar_t string, for example, L"hao123--我的上网主页", I can convert it to utf8 encoding, the output string is "hao123锛嶏紞鎴戠殑涓婄綉涓婚〉", but finally, I must write this string to a plain text file, its format is utf16 (I know this from others),…
Dan
  • 3,221
  • 7
  • 27
  • 24
1
vote
0 answers

basic_string not found during linking

I am compiling in Visual Studio 10 a library developed by myself that uses Boost 1.55.0 and a third-party library, but I obtain the errors below during the linking phase. The third-party library developer told me to recompile all the codes (my code…
davide
  • 221
  • 3
  • 16
1
vote
4 answers

How to copy a wchar_t into an NSString?

I'm using stringWithFormat @"%ls" to do it and I only see the first character copied, which makes me think it's still assuming it's a single byte char. Any ideas?
glutz78
  • 181
  • 1
  • 2
  • 8
1
vote
3 answers

XMLCh to wchar_t and vice versa

My config: Compiler: gnu gcc 4.8.2 I compile with C++11 platform/OS: Linux 64bit Ubuntu 14.04.1 LTS I want to feed a method with wchar_t* and use it in many xecerces library methods that need XMLCh* but I don't know how to translate from one to…
mimosa
  • 125
  • 3
  • 13
1
vote
2 answers

MATLAB wchar_t Equivalent Type

The C-Code is stored in a DLL. I can load the DLL in MATLAB with the loadlibrary function. I am having trouble passing the wchar_t*[] parameter to the function. I do not know how to create this data type in MATLAB. Does anyone know how to create…
John
  • 11
  • 2
1
vote
1 answer

swprintf fails with \xffff unicode characters

The following lines of code running with Visual Studio 2013: wchar_t test[] = L"\xffff"; wchar_t buf[100]; int ret = swprintf(&buf[0], 100, L"%ls", &test[0]); It compiles successfully, but swprintf fails to output this character (res is -1).…
muzdima
  • 23
  • 1
  • 4
1
vote
1 answer

C++ count matches regex function that works with both char and wchar_t?

With the answer from this question I was able to create a function that uses regex to find and replace in strings that works with both char and wchar_t template basic_string replaceString(const CharT* find, const…
fxfuture
  • 1,910
  • 3
  • 26
  • 40
1
vote
1 answer

pin_ptr & PtrToStringChars vs. StringToHGlobalAnsi: Why does PtrToStringChars var loose its value?

I am using C++/CLI and I want to call the function WNetAddConnection2 from Windows Networking. First, I know that C++/CLI is not the language of choice for my work, but I have no possibility to change that right now and e.g. use C# instead. The…
Tobias Knauss
  • 3,361
  • 1
  • 21
  • 45
1
vote
2 answers

difference between integral value of wchar_t character in two situation

When I use this code to obtain integral value of 'س' in unicode I get 1587 (that is 633 in hex). This is right value of 'س' in unicode standard. wchar_t wc = L'س'; cout<
JalalJaberi
  • 2,417
  • 8
  • 25
  • 41
1
vote
0 answers

vswprintf(VS 2008) expects %s to be converted to %ls in the argument

I'm converting the formatted strings to a single wchar_t*. When I have a stream containing %s, vswprintf somehow doesn't form a expected wchar_t* out of that formatted string. This is happening only in Windows(VS 2008) but works well in Mac (XCode…