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

Getting the length of a formatted string from wsprintf

When using standard char* strings, the snprintf and vsnprintf functions will return the length of the output string, even if that string was truncated due to overflow.* It seems like the ISO C committee didn't like this functionality when they added…
justinian
  • 300
  • 2
  • 8
1
vote
2 answers

C++ Microsoft example to get and display the user name doesn't compile

I want to get the user name in C++ in the most easiest way. My program is only designed for Windows. I would like to use the Microsoft example. I copy paste the code example in a fresh Visual Studio 2019 but I have errors on TEXT instruction: a…
user13339912
1
vote
2 answers

C Wide characters - how to use them?

I'm able to output a single character using this code: #include #include #include main(){ setlocale(LC_CTYPE, ""); wchar_t a = L'Ö'; putwchar(a); } How can I adapt the code to output a string? Something…
Frank Vilea
  • 8,323
  • 20
  • 65
  • 86
1
vote
1 answer

Anybody know a non-ascii encoding?

'1' use two bytes 20 and 0; '2' use two bytes 21 and 0; 'a' use two bytes 68 and 0; 'b' use two bytes 69 and 0; I'm hook func ExtTextOutW from GDI32.dll(windowsapi) ,and read from str(unsigned char); such as abc123... while got:68 0 69 0 70 0 20 0…
mouwang
  • 31
  • 4
1
vote
1 answer

What is the issue in following conversion from argv[1] to char * string?

I am very new to C and pointers. I am trying to convert command line argument to wchar_t * . But somehow it is not giving proper output. What am I missing? void fun(){ std::setlocale(LC_ALL, "en_US.utf8"); …
1
vote
2 answers

Access violation when converting from uint32_t to wchar_t and storing in wstring

This might be a simple question, but I have a value in DirectXTDK that is in uint32_t. I would like to display this by concatenating it with a wchar_t. This is what I have so far - char buffer[1]; wchar_t* ws1 = (wchar_t…
firepro20
  • 63
  • 1
  • 8
1
vote
1 answer

wcslen() returns incorrect result when pragma pack used

I've found that wcslen() returns incorrect result on gcc(and correct on msvc) when source is wchar_t array, member of packed struct. I know on linux sizeof(wchar_t) == 4 and on windows its 2 but still can't understand how packing affects wcslen()…
Alex
  • 13
  • 5
1
vote
2 answers

Reading Byte Data through the serial port in C++/CLI

I am trying to make an interface with another program so I have to use C++. It's been years since I have programmed in C++ and I have been at this problem for about a week so I'm slowly starting to see how everything works. I want to read byte data…
newb_k1dd
  • 21
  • 2
  • 3
1
vote
1 answer

Access violation while copying a string of wchar from network packet

I'm programming game server and it uses unicode since I'm in Korea. The problem is that I can't copy wchar string from packet. I checked wcsncpy_s(chat, 100, inChat.c_str(), inChat.length()); this works fine but something like this doesn't…
Jeongmin Heo
  • 61
  • 1
  • 7
1
vote
2 answers

How to concatenate string in _bstr_t and wchar_t?

I have _bstr_t string and I have wchar_t and one unsigned int variables which I want to put to the string... _bstr_t strCnn("Driver={SQL Server};Server=some_host,some_port;Database=some_db;User ID=some_user;Password=some_psw;"); wchar_t…
Nikola
  • 29
  • 5
1
vote
2 answers

OCI,OCILIB,ODBC wide character(wchar) support

Which of these libraries OCI,OCILIB,ODBC or any other support wide character strings (wchar) ?
Greenhorn
  • 658
  • 2
  • 8
  • 24
1
vote
3 answers

Similar conversion in overloading wstring and wchar_t *

I have following code: inline bool match(const std::wstring & text1, const std::wstring & text2) { return match(text1.c_str(), text2.c_str()); } inline bool match(const std::wstring & text1, const wchar_t * text2) { return…
relaxxx
  • 7,566
  • 8
  • 37
  • 64
1
vote
1 answer

Problem with Unicode in C++ exe (MSVC++2010)

I have a strange problem which I don't know where it came from. I might have changed some settings in the MSVC++2010 project but it all looks good to me. I'm currently experimenting with the VSHADOW.EXE 3.0 tool included with Windows SDK 6.1. This…
Felix Dombek
  • 13,664
  • 17
  • 79
  • 131
1
vote
1 answer

How can I store a unicode in C?

I am trying to store a Unicode codepoint inside a variable in C. I tried using wchar_t, however since the Unicode codepoint I am trying to store is U+1F319, it doesn't fit in wchar_t. How can I get around this? I'm using a Windows…
coderhk
  • 286
  • 2
  • 14
1
vote
3 answers

How to widen a standard string while maintaining the characters?

I have a function to take a std::string and change it into a wchar_t*. My current widen function looks like this wchar_t* widen(const std::string& str){ wchar_t * dest = new wchar_t[str.size()+1]; char * temp = new char[str.size()]; …
WWZee
  • 494
  • 2
  • 8
  • 23