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

How can I read a text file containing Unicode, into a wchar_t pointer using wifstream?

I'm trying to read Unicode characters from a text file into a wchar_t pointer array, using wifstream. Here is a code snippet: locale::global(std::locale("en_US.UTF-8")); std::wifstream inputFile("gsmCharacterSet.txt", std::ifstream::binary |…
yogur
  • 810
  • 10
  • 19
1
vote
1 answer

C - wchar_t prints unwanted characters

Hey. I am trying to list a folder which has non-english character files. Below function takes an argument, say C:\ and lists the files inside it. But not 100% correctly. For Turkish characters it prints some symbols, even though I used wchar_t…
mert yeniay
  • 39
  • 1
  • 6
1
vote
6 answers

Struct Not Accepting wchar_t

That's the only thing I can think of. The thing is sentient. I have a struct as follows: struct NumPair { wchar_t *pFirst, *pSecond; int count; with ctor, copy assignment and construction as NumPair( wchar_t *pfirst, wchar_t *psecond, int…
IAE
  • 2,213
  • 13
  • 37
  • 71
1
vote
2 answers

How to change wchar.h to make wchar_t the same type as wint_t?

wchar_t is defined in wchar.h Currently, if the developers want to use only wchar_t, they can not do this without getting type conversion warnings from the compiler. If wchar_t will be made the same type as wint_t, it will be good for both…
Igor Liferenko
  • 1,499
  • 1
  • 13
  • 28
1
vote
2 answers

How multibyte string is converted to wide-character string in fxprintf.c in glibc?

Currently, the logic in glibc source of perror is such: If stderr is oriented, use it as is, else dup() it and use perror() on dup()'ed fd. If stderr is wide-oriented, the following logic from stdio-common/fxprintf.c is used: size_t len = strlen…
Igor Liferenko
  • 1,499
  • 1
  • 13
  • 28
1
vote
0 answers

read a textfile using mmap, wchar_t

The last few hours I am banging my head against the wall and actually do not really understand what's going wrong here. I have a text file containing word phrases not longer than 128 characters. What I try to do is memory map this file and read of…
Andreas W. Wylach
  • 723
  • 2
  • 10
  • 31
1
vote
2 answers

Determining best practice when using wide characters with non-compatible char API's

Alright, so I've recently dipped back into C++. It's been 13 years since I've even looked at any C/++ code. I am designing a piece of software for Windows and what I am struggling with is implementing 3rd party code (such as libssh2) that is…
user0000001
  • 2,092
  • 2
  • 20
  • 48
1
vote
5 answers

Need to convert char* (pointer) to wchar_t* (pointer)

I am doing some serial port communcation to a computer controlled pump and the createfile function I used to communicate requires the com port name to be parsed as a wchar_t pointer. I am also using QT to create a form and aquire the com port name…
Zac
  • 2,229
  • 9
  • 33
  • 41
1
vote
3 answers

C++: Files, encodings and datatypes

---- PLEASE CLOSE ---- ------ Edit --------- I found where the problem is. I'm going to start a new question for the real problem .... ----------------------   Hi, My Situation: Linux (Ubuntu 10.04) gcc But it has to be platform independent I…
Martijn Courteaux
  • 67,591
  • 47
  • 198
  • 287
1
vote
0 answers

Split wchar_t string defined using pointer into constituent wchar_t characters in C

I would like to split a wchar_t string defined using pointer to its constituent wchar_t characters in C. i.e, if wchar_t *wcs = L"बहन" , then the output should be ब ह न I tried the below 2 code snippets, but failed to get the desired…
1
vote
2 answers

string literal - template conversion between char types

I would like to code a function that would look like: template std::basic_string convert(char const *); and be used as follows: convert("Hello World!"); // "Hello World!" convert("Hello World!"); //…
O'Neil
  • 3,790
  • 4
  • 16
  • 30
1
vote
1 answer

Are fputwc and fgetwc significantly faster than fprintf and fscanf? Why is it so?

I am working on files using characters of wcahr_t type. I would like to make my program faster. Does it make any sense to substitute fprintf with fputwc and fscanf with fgetwc wherever possible? If so, why?
Mateusz Piotrowski
  • 8,029
  • 10
  • 53
  • 79
1
vote
1 answer

Initialization of a wchar_t array with wmemset. Does encoding matter?

How do I correctly initialize a wchar_t array with wmemset? Should I use '\0' or L'\0' ? Does it matter? does the encoding matter ? (unicode, ISO####) eg wchar_t arr[20]; wmemset(arr, '\0', sizeof(arr));
thahgr
  • 718
  • 1
  • 10
  • 27
1
vote
4 answers

Returning a wchar_t in C++

I'm making a function that return a pointer to a wchar_t, but it returns nothing each time I use it. Function: wchar_t *Character::getCharHealth() { wchar_t charHealth[256]; swprintf_s(charHealth, L"%d", this->getHealth()); …
user3138585
1
vote
6 answers

Whats the easiest way to convert a long in C to a char*?

What is the clean way to do that in C? wchar_t* ltostr(long value) { int size = string_size_of_long(value); wchar_t *wchar_copy = malloc(value * sizeof(wchar_t)); swprintf(wchar_copy, size, L"%li", self); return wchar_copy; } The…
camillobruni
  • 2,298
  • 16
  • 26