wchar-t

How to initialize a wchar_t variable?

廉价感情. 提交于 2019-11-29 02:12:05
I am reading the book: C: In a Nutshell , and after reading the section Character Sets , which talks about wide characters, I wrote this program: #include <stdio.h> #include <stddef.h> #include <wchar.h> int main() { wchar_t wc = '\x3b1'; wprintf(L"%lc\n", wc); return 0; } I then compiled it using gcc, but gcc gave me this warning: main.c:7:15: warning: hex escape sequence out of range [enabled by default] And the program does not output the character α (whose unicode is U+03B1), which is what I wanted it to do. How do I change the program to print the character α? This works for me #include

how to convert char array to wchar_t array?

邮差的信 提交于 2019-11-28 12:07:34
char cmd[40]; driver = FuncGetDrive(driver); sprintf_s(cmd, "%c:\\test.exe", driver); I cannot use cmd in sei.lpFile = cmad; so, how to convert char array to wchar_t array ? Traveling Tech Guy From MSDN : #include <iostream> #include <stdlib.h> #include <string> using namespace std; using namespace System; int main() { char *orig = "Hello, World!"; cout << orig << " (char *)" << endl; // Convert to a wchar_t* size_t origsize = strlen(orig) + 1; const size_t newsize = 100; size_t convertedChars = 0; wchar_t wcstring[newsize]; mbstowcs_s(&convertedChars, wcstring, origsize, orig, _TRUNCATE);

Display wchar_t using ncurses

浪子不回头ぞ 提交于 2019-11-28 11:48:39
i'm currently working on a C++ project in which I need to display some extended characters (wchar_t). The main problem is that, even if it works fine in C (using wprintf ), it doesn't work in c++ using mvwaddwstr or waddwstr . Of course, i've set the locale like that: setlocale(LC_ALL, ""); , and nothing is displayed. Does someone got this problem before, or has an idea about that? Thanks. Here is the code: struct charMap { int x; int y; wchar_t value }; int i, x, y; wchar_t str[2]; struct charMap _charMap[2] = { {0,0,9474} {29, 29, 9474} }; initscr(); setlocale(LC_ALL, ""); for (y = 0 ; y <

How do I convert wchar_t* to std::string?

喜欢而已 提交于 2019-11-28 09:37:34
I changed my class to use std::string (based on the answer I got here but a function I have returns wchar_t *. How do I convert it to std::string? I tried this: std::string test = args.OptionArg(); but it says error C2440: 'initializing' : cannot convert from 'wchar_t *' to 'std::basic_string<_Elem,_Traits,_Ax>' You could just use wstring and keep everything in Unicode wstring ws( args.OptionArg() ); string test( ws.begin(), ws.end() ); You can convert a wide char string to an ASCII string using the following function: #include <locale> #include <sstream> #include <string> std::string ToNarrow

Writing Unicode Characters to an OStream

﹥>﹥吖頭↗ 提交于 2019-11-28 08:00:08
问题 I'm working with unicode/wide characters and I'm trying to create a toString method (Java ::toString equiv). Will ostream handle wide characters, if so is there a way to warn the consumer of the stream that it is unicode coming out of it? 回答1: Neither ostream nor the rest of C++ know anything about Unicode. Usually you write a string conversion in C++ as follows: template<typename Char, typename Traits> std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& stream,

cannot convert 'const char*' to 'LPCWSTR {aka const wchar_t*}'

大憨熊 提交于 2019-11-28 02:16:33
I'm getting an error in my C++ code that I can't quite make sense of. The stripped down code bits are here: RS232Handle=OpenRS232("COM1", 9600); HANDLE OpenRS232(const char* ComName, DWORD BaudRate) { ComHandle=CreateFile(ComName, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); } I get the following error: error: cannot convert 'const char*' to 'LPCWSTR {aka const wchar_t*}' for argument '1' to 'void* CreateFileW(LPCWSTR, DWORD, DWORD, LPSECURITY_ATTRIBUTES, DWORD, DWORD, HANDLE)' ComHandle=CreateFile(ComName, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING

How do i convert const wchar_t* to System::String?

不问归期 提交于 2019-11-28 01:35:17
问题 I need to convert my SHA1 (wchar_t*) to a normal String^ in order to use it in a certain function. Any ideas? I tried Google but all the results were the exact opposite of my question. :\ NOTE: I am using C++.NET framework and Windows Forms Applications 回答1: Use the constructor; like this: const wchar_t* const pStr1 = ...; System::String^ const str1 = gcnew System::String(pStr1); const char* const pStr2 = ...; System::String^ const str2 = gcnew System::String(pStr2); If you're using the

Is endian conversion required for wchar_t data?

人盡茶涼 提交于 2019-11-28 00:36:44
问题 In C/C++, if a multi-byte wide character (wchar_t) value is transmitted from a big-endian system to a little-endian system (or vice-versa), will it come out the same value on the other side? Or will the bytes need to be swapped? 回答1: Yes you will need to swap them. The bytes will be retrieved from the transport in the same order they were put in. Just at the other end the ordering of these bytes has a different meaning. So you need to convert them to the correct endian-ness (is that a word?).

How to initialize a wchar_t variable?

两盒软妹~` 提交于 2019-11-27 16:44:44
问题 I am reading the book: C: In a Nutshell , and after reading the section Character Sets , which talks about wide characters, I wrote this program: #include <stdio.h> #include <stddef.h> #include <wchar.h> int main() { wchar_t wc = '\x3b1'; wprintf(L"%lc\n", wc); return 0; } I then compiled it using gcc, but gcc gave me this warning: main.c:7:15: warning: hex escape sequence out of range [enabled by default] And the program does not output the character α (whose unicode is U+03B1), which is

How to convert concatenated strings to wide-char with the C preprocessor?

◇◆丶佛笑我妖孽 提交于 2019-11-27 15:12:33
I am working on a project where I have many constant strings formed by concatenation (numbers, etc.). For example, I have a LOCATION macro that formats __FILE__ and __LINE__ into a string that I can use to know where I am in the code, when printing messages or errors: #define _STR(x) # x #define STR(x) _STR(x) #define LOCATION __FILE__ "(" STR(__LINE__) ")" So, this would format a location like "file.cpp(42)". The problem is when I try to convert the result to a wide-string: #define _WIDEN(x) L ## x #define WIDEN(x) _WIDEN(x) #define WLOCATION WIDEN(LOCATION) This works just fine with GCC, and