wchar-t

How to concat an int to a wchar_t* in C++?

爷,独闯天下 提交于 2019-12-10 18:38:32
问题 I have to create and write on N files, everyone must have an integer ending to identificate it. This is my piece of code: for(int i=0; i<MAX; i++) { uscita.open("nameFile"+i+".txt", ios::out); uscita << getData() << endl; uscita.close(); } And that's what I would like to find in my directory after execution: nameFile0.txt nameFile1.txt nameFile2.txt ... nameFileMAX.txt The problem of the above code is that I get the compilin' error: error C2110: '+' Impossible to add two pointers If I try to

How to convert wstring to wchar_t*? C++

有些话、适合烂在心里 提交于 2019-12-10 12:34:50
问题 I would like to convert wstring to wchar_t*. I have tried everything what i know, please help. I would like to convert wstring to wchar_t*. 回答1: Did you try reading the reference const wchar_t* wcs = s.c_str(); 回答2: There is no way to convert wstring to wchar_t* but you can convert it to const wchar_t* which is what answer by K.Kirsz says. This is by design because you can access a const pointer but you shouldn't manipulate the pointer. See a related question and its answers. The best bet is

Why is char neither signed or unsigned, but wchar_t is?

て烟熏妆下的殇ゞ 提交于 2019-12-10 03:57:51
问题 The following C++ program compiles without errors: void f(char){} void f(signed char){} void f(unsigned char){} int main(){} The wchar_t version of the same program does not: void f(wchar_t){} void f(signed wchar_t){} void f(unsigned wchar_t){} int main(){} error: redefinition of ‘void f(wchar_t)’ void f(signed wchar_t){} It seems that wchar_t is unsigned . Why is there an inconsistency in overloading? 回答1: The char s are all distinct types and can be overloaded [basic.fundamental] / 1 [...]

Cross-platform unicode in C/C++: Which encoding to use?

孤人 提交于 2019-12-10 02:43:10
问题 I'm currently working on a hobby project (C/C++) which is supposed to work on both Windows and Linux, with full support for Unicode. Sadly, Windows and Linux use different encodings making our lives more difficult. In my code I'm trying to use the data as universal as possible, making it easy for both Windows and Linux. In Windows, wchar_t is encoded as UTF-16 by default, and as UCS-4 in Linux (correct me if I'm wrong). My software opens ({_wfopen, UTF-16, Windows},{fopen, UTF-8, Linux}) and

Does the C++ standard mandate an encoding for wchar_t?

北城以北 提交于 2019-12-09 06:35:33
问题 Here are some excerpts from my copy of the 2014 draft standard N4140 22.5 Standard code conversion facets [locale.stdcvt] 3 For each of the three code conversion facets codecvt_utf8 , codecvt_utf16 , and codecvt_utf8_utf16 : (3.1) — Elem is the wide-character type, such as wchar_t , char16_t , or char32_t . 4 For the facet codecvt_utf8 : (4.1) — The facet shall convert between UTF-8 multibyte sequences and UCS2 or UCS4 (depending on the size of Elem ) within the program. One interpretation of

Reading/writing/printing UTF-8 in C++11

蓝咒 提交于 2019-12-08 16:25:38
问题 I have been exploring C++11's new Unicode functionality, and while other C++11 encoding questions have been very helpful, I have a question about the following code snippet from cppreference. The code writes and then immediately reads a text file saved with UTF-8 encoding. // Write std::ofstream("text.txt") << u8"z\u6c34\U0001d10b"; // Read std::wifstream file1("text.txt"); file1.imbue(std::locale("en_US.UTF8")); std::cout << "Normal read from file (using default UTF-8/UTF-32 codecvt)\n"; for

Assigning non-ASCII characters to wide char and printing with printf

折月煮酒 提交于 2019-12-07 15:08:46
问题 How can I assign non-ASCII characters to a wide char and print it to the console? This code down doesn't work: #include <stdio.h> int main(void) { wchar_t wc = L'ć'; printf("%lc\n", wc); printf("%ld\n", wc); return 0; } Output: 263 Press [Enter] to close the terminal ... I'm using MinGW GCC on Windows 7. 回答1: I think your calls to printf() fail with an «Illegal byte sequence» error returned in errno , at least that is what happens here on MacOS X with the above example code (and also if using

How to convert wchar_t** to char**?

我的梦境 提交于 2019-12-07 08:47:49
问题 I get argv as wchar_t** (see below), because I need to work with unicode, but I need to convert it to char **. How can I do that? int wmain(int argc, wchar_t** argv) { 回答1: There is more than one way to do this. Depending on your environment and available compiler/standard library/other libraries, you have at least three choices: Use std::locale and std::codecvt<> facet; use C locale functions like std::mbstowcs(); use 3rd party functions like iconv() on *nix or WideCharToMultiByte() on

How do you efficiently copy BSTR to wchar_t[]?

廉价感情. 提交于 2019-12-07 06:25:56
问题 I have a BSTR object that I would like to convert to copy to a wchar__t object. The tricky thing is the length of the BSTR object could be anywhere from a few kilobytes to a few hundred kilobytes. Is there an efficient way of copying the data across? I know I could just declare a wchar_t array and alway allocate the maximum possible data it would ever need to hold. However, this would mean allocating hundreds of kilobytes of data for something that potentially might only require a few

Portable wchar_t in C++

六月ゝ 毕业季﹏ 提交于 2019-12-07 05:37:08
问题 Is there a portable wchar_t in C++? On Windows, its 2 bytes. On everything else is 4 bytes. I would like to use wstring in my application, but this will cause problems if I decide down the line to port it. 回答1: If you're dealing with use internal to the program, don't worry about it; a wchar_t in class A is the same as in class B. If you're planning to transfer data between Windows and Linux/MacOSX versions, you've got more than wchar_t to worry about, and you need to come up with means to