wchar-t

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

谁都会走 提交于 2020-07-10 04:15:08
问题 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 | std::ifstream::ate); int length = inputFile.tellg(); inputFile.seekg(0,inputFile.beg); wchar_t *charArray = new wchar_t[length]; inputFile.read(charArray,length); It's not working. The length returned is 252 which is the correct file size in bytes.

Unable to create an array of wchar_t

◇◆丶佛笑我妖孽 提交于 2020-07-07 11:50:14
问题 In my code I have an array of wchar_t: wchar_t paths [6] = {L"C:\\Program Files\\SomeAppsSuiteFolder1", L"C:\\Program Files\\SomeAppsSuiteFolder2", L"C:\\Program Files (x86)\\SomeAppsSuiteFolder1", L"C:\\Program Files (x86)\\SomeAppsSuiteFolder2", L"C:\\SomeAppsSuiteFolder1", L"C:\\SomeAppsSuiteFolder2"}; Later on I use the array in for loop. The problem is, that for this line I get following errors: error: too many initializers for 'wchar_t [6]' error: initializer-string for array of chars

Unable to create an array of wchar_t

血红的双手。 提交于 2020-07-07 11:49:50
问题 In my code I have an array of wchar_t: wchar_t paths [6] = {L"C:\\Program Files\\SomeAppsSuiteFolder1", L"C:\\Program Files\\SomeAppsSuiteFolder2", L"C:\\Program Files (x86)\\SomeAppsSuiteFolder1", L"C:\\Program Files (x86)\\SomeAppsSuiteFolder2", L"C:\\SomeAppsSuiteFolder1", L"C:\\SomeAppsSuiteFolder2"}; Later on I use the array in for loop. The problem is, that for this line I get following errors: error: too many initializers for 'wchar_t [6]' error: initializer-string for array of chars

Using iconv with WCHAR_T on Linux

扶醉桌前 提交于 2020-06-01 06:20:06
问题 I have the following code on Linux:- rc = iconv_open("WCHAR_T", SourceCode); prior to using iconv to convert the data into a wide character string ( wchar_t ). I am trying to understand what it achieves in order to port it to a platform where the option on parameter 1, "WCHAR_T" , does not exist. This leads to sub-questions such as: Is there a single representation of wchar_t on Linux? What codepage does this use? I imagine maybe UTF-32 Does it rely on any locale settings to achieve this? I'm

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

て烟熏妆下的殇ゞ 提交于 2020-02-05 05:12:46
问题 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 (fmt) + 1; wchar_t wfmt[len]; for (size_t i = 0; i < len; ++i) { assert (isascii (fmt[i])); wfmt[i] = fmt[i]; } res = __vfwprintf (fp, wfmt, ap); The format string is converted to wide-character form by the following code, which I do not understand:

Outputting 'wchar_t*' to an 'ofstream'

孤人 提交于 2020-01-29 06:02:25
问题 I want to output a text to a file via two pointers that I have declared: wchar_t *Col1="dsffsd", *Col2="sdfsf"; Here is what I have tried: std::ofstream fout; fout.open(NativeDatabasePathHist); fout<<"testing"; fout<<" "<<Col1<<" "<<Col2; fout.close(); And here is what I am getting: testing 113 113 Why is it that when I print Col1 and Col2 , I am getting numbers instead of strings? 回答1: First, use std::wofstream instead of std::ofstream . Also, use the L prefix on your text string to indicate

Outputting 'wchar_t*' to an 'ofstream'

空扰寡人 提交于 2020-01-29 06:01:25
问题 I want to output a text to a file via two pointers that I have declared: wchar_t *Col1="dsffsd", *Col2="sdfsf"; Here is what I have tried: std::ofstream fout; fout.open(NativeDatabasePathHist); fout<<"testing"; fout<<" "<<Col1<<" "<<Col2; fout.close(); And here is what I am getting: testing 113 113 Why is it that when I print Col1 and Col2 , I am getting numbers instead of strings? 回答1: First, use std::wofstream instead of std::ofstream . Also, use the L prefix on your text string to indicate

isalpha equivalent for wchar_t

空扰寡人 提交于 2020-01-14 07:39:05
问题 what is the equivalent function for isalpha or isalnum using wchar_t? wctype ? an example would be nice also thanks 回答1: iswalpha , iswalnum . Same usage. Docs - Windows (msdn) iswalpha iswalnum Docs - Linux (opengroup.org) iswalpha iswalnum 回答2: You include tag "localization" in your question. In case of writing of international application you should clear define what do you mean under alphabetical or numerical characters . If you write programs for Windows I'll recommend you to use

Why does `std::basic_ifstream<char16_t>` not work in c++11?

蹲街弑〆低调 提交于 2020-01-10 20:14:05
问题 The following code works as expected. The source code, file "file.txt" and "out.txt" are all encoded with utf8. But it does not work when I change wchar_t to char16_t at the first line in main() . I've tried both gcc5.4 and clang8.0 with -std=c++11 . My goal is to replace wchar_t with char16_t , as wchar_t takes twice space in RAM. I thought these 2 types are equally well supported in c++11 and later standards. What do I miss here? #include<iostream> #include<fstream> #include<locale>

Can't copy unicode(used wchar_t) in HTML format to clipboard

爱⌒轻易说出口 提交于 2020-01-06 19:45:10
问题 Copying to clipboard in HTML format works when I use char , but if I use wchar_t it doesn't work When I paste it it's just EMPTY here is my code Plase Help me Or is there a better way to use unicode(not using wchar_t)? If you do help me void copyStringEnd(wchar_t *string, wchar_t *buffer) { int i = 0; int string_StartIndex = 0; while (string[string_StartIndex] != NULL) { string_StartIndex++; } while (buffer[i] != NULL) { string[string_StartIndex + i] = buffer[i]; i++; } string[string