wchar

char* to const wchar_t * conversion

核能气质少年 提交于 2019-12-07 06:13:49
问题 I need to convert character pointer to a w_char * in order to use ParseNetworkString(). I've tried finding solutions to this myself, and while I have found one solution, there is one issue which blocks me from using it: b1naryatr0phy said in an other post: std::wstring name( L"Steve Nash" ); const wchar_t* szName = name.c_str(); this almost works for me, except that I can't just pass the string explicity, as its value is not always going to be the same, meaning I can't just put it in quotes.

char* to const wchar_t * conversion

空扰寡人 提交于 2019-12-05 09:39:38
I need to convert character pointer to a w_char * in order to use ParseNetworkString(). I've tried finding solutions to this myself, and while I have found one solution, there is one issue which blocks me from using it: b1naryatr0phy said in an other post: std::wstring name( L"Steve Nash" ); const wchar_t* szName = name.c_str(); this almost works for me, except that I can't just pass the string explicity, as its value is not always going to be the same, meaning I can't just put it in quotes. If I replace the parameter with a function call, then the first line gives me an error (example: std:

Print wchar to Linux console?

梦想与她 提交于 2019-12-03 03:12:08
My C program is pasted below. In bash, the program print "char is ", Ω is not printed. My locale are all en_US.utf8. #include <stdio.h> #include <wchar.h> #include <stdlib.h> int main() { int r; wchar_t myChar1 = L'Ω'; r = wprintf(L"char is %c\n", myChar1); } This was quite interesting. Apparently the compiler translates the omega from UTF-8 to UNICODE but somehow the libc messes it up. First of all: the %c -format specifier expects a char (even in the wprintf -version) so you have to specify %lc (and therefore %ls for strings). Secondly if you run your code like that the locale is set to C

Wide character output result [closed]

北慕城南 提交于 2019-12-02 13:24:02
Why do I get numbers as output result when using wchar_t? #include <iostream> using namespace std; int main() { wchar_t q; q = 'A'; cout << q; q = 'B'; cout << q; q = 'C'; cout << q; return 0; } The displayed 'numbers' are the value of the character. That's the reason you get 'numbers'. If you want to display the characters you can use wcout std::cout is a basic_iostream<char> . There is no operator<< overload for wchar_t for basic_iostream<char> . When you output wchar_t objects they must be converted to some type for which there is an operator<< overload. The selected conversion is to an

C++ regex with char and wchar_t?

蹲街弑〆低调 提交于 2019-12-01 21:59:04
问题 I have a const char and a const wchar_t. My function below works with the char. What's the simplest/most efficient way to write a function that can easily handle both char and wchar_t? const char* asciiChar = "this is an ascii string"; const wchar_t* unicodeChar = L"this is a unicode string"; std::string replaceSubstring(const char* find, const char* asciiChar, const char* replace) { std::string const text(str); std::regex const reg(find); std::string const newStr = std::regex_replace(text,

C++ regex with char and wchar_t?

丶灬走出姿态 提交于 2019-12-01 21:22:54
I have a const char and a const wchar_t. My function below works with the char. What's the simplest/most efficient way to write a function that can easily handle both char and wchar_t? const char* asciiChar = "this is an ascii string"; const wchar_t* unicodeChar = L"this is a unicode string"; std::string replaceSubstring(const char* find, const char* asciiChar, const char* replace) { std::string const text(str); std::regex const reg(find); std::string const newStr = std::regex_replace(text, reg, replace); return newStr; } For this reason exactly, regex is a typedef of basic_regex<char> , much

Is it safe to return std::wstring from a DLL?

流过昼夜 提交于 2019-12-01 18:13:44
According to some older StackOverflow questions ( Unable to pass std::wstring across DLL , C++ DLL returning pointer to std::list<std::wstring> ) it's not considered safe for a C++ DLL to return a std::wstring because there's no guarantee the main program has the same definition of std::wstring and therefore it might cause a crash. However, in http://en.cppreference.com/w/cpp/string/basic_string , it seems std::wstring can be used interchangeably with a WCHAR array now: (Since C++11) The elements of a basic_string are stored contiguously, that is, for a basic_string s, &*(s.begin() + n) == &*s

Convert char* to wchar* in C

蹲街弑〆低调 提交于 2019-11-30 07:25:53
问题 I would like to convert a char* string to a wchar* string in C. I have found many answers, but most of them are for C++. Could you help me? Thanks. 回答1: Try swprintf with the %hs flag. Example: wchar_t ws[100]; swprintf(ws, 100, L"%hs", "ansi string"); 回答2: setlocale() followed by mbstowcs(). 回答3: what you're looking for is mbstowcs works just like the copy function from char* to char* but in this case you're saving into a wchar_t* 回答4: If you happen to have the Windows API availiable, the

Pass a function pointer from C++ to be called by C# - Arguments of functions include a wide char string (LPCWSTR)

谁都会走 提交于 2019-11-29 11:37:07
I am writing a C# library to be used by native C++ application. I am using C++/CLI as the Interoperability mechanisim. I require to pass a callback function from C++ to C# (using C++/CLI as the intermediate layer). C# library needs to call the C++ function with a zero terminated string of wide characters; i.e. the prototype of the callback function is Func(LPCWSTR pszString); There are other parameters but they are immaterial for this discussion. I searched net and found Marshal.GetDelegateForFunctionPointer Method wich I can use. The problem with this is that it converts System.String from C#

Convert char* to wchar* in C

时间秒杀一切 提交于 2019-11-29 03:47:24
I would like to convert a char* string to a wchar* string in C. I have found many answers, but most of them are for C++. Could you help me? Thanks. Try swprintf with the %hs flag. Example: wchar_t ws[100]; swprintf(ws, 100, L"%hs", "ansi string"); Mehrdad setlocale() followed by mbstowcs() . what you're looking for is mbstowcs works just like the copy function from char* to char* but in this case you're saving into a wchar_t* If you happen to have the Windows API availiable, the conversion function MultiByteToWideChar offers some configurable string conversion from different encodings to UTF