char16-t

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>

char16_t and char32_t endianness

大兔子大兔子 提交于 2019-12-13 16:43:21
问题 In C11, support for portable wide char types char16_t and char32_t are added for UTF-16 and UTF-32 respectively. However, in the technical report, there is no mention of endianness for these two types. For example, the following snippet in gcc-4.8.4 on my x86_64 computer when compiled with -std=c11 : #include <stdio.h> #include <uchar.h> char16_t utf16_str[] = u"十六"; // U+5341 U+516D unsigned char *chars = (unsigned char *) utf16_str; printf("Bytes: %X %X %X %X\n", chars[0], chars[1], chars[2

C++11 char16_t strlen-equivalent function

自作多情 提交于 2019-12-10 02:09:31
问题 I have a simple question: Is there a way to do a strlen() -like count of characters in zero-terminated char16_t array? 回答1: use char_traits<char16_t>::length(your_pointer) see 21.2.3.2 struct char_traits<char16_t> and table 62 of the C++11-Std. 回答2: Use pointers :), create a duplicate pointer to the start, then loop through it while (*endptr++); , then the length is given by endptr - startptr . You can actually template this, however, its possible the the compile won't generate the same

C++11 char16_t strlen-equivalent function

拈花ヽ惹草 提交于 2019-12-05 00:20:47
I have a simple question: Is there a way to do a strlen() -like count of characters in zero-terminated char16_t array? use char_traits<char16_t>::length(your_pointer) see 21.2.3.2 struct char_traits<char16_t> and table 62 of the C++11-Std. Necrolis Use pointers :), create a duplicate pointer to the start, then loop through it while (*endptr++); , then the length is given by endptr - startptr . You can actually template this, however, its possible the the compile won't generate the same intrinsic code it does for strlen (for different sizes ofc). 来源: https://stackoverflow.com/questions/5818508

New unicode characters in C++0x

隐身守侯 提交于 2019-12-03 06:44:05
问题 I'm buiding an API that allows me to fetch strings in various encodings, including utf8, utf16, utf32 and wchar_t (that may be utf32 or utf16 according to OS). New C++ standard had introduced new types char16_t and char32_t that do not have this sizeof ambiguity and should be used in future, so I would like to support them as well, but the question is, would they interfere with normal uint16_t , uint32_t , wchar_t types not allowing overload because they may refer to same type? class some

Visual Studio C++ 2015 std::codecvt with char16_t or char32_t

别说谁变了你拦得住时间么 提交于 2019-11-27 22:43:00
This code compiled OK under VS2013: std::string Unicode::utf16_to_utf8(std::u16string utf16_string) { std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert; return convert.to_bytes(utf16_string); } Now with VS2015 I get: 1>unicode.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static class std::locale::id std::codecvt<char16_t,char,struct _Mbstatet>::id" (__imp_?id@?$codecvt@_SDU_Mbstatet@@@std@@2V0locale@2@A) Old question, but for future reference: this is a known bug in Visual Studio 2015, as explained in the latest post (January 7th 2016)

Visual Studio C++ 2015 std::codecvt with char16_t or char32_t

人走茶凉 提交于 2019-11-27 17:09:43
问题 This code compiled OK under VS2013: std::string Unicode::utf16_to_utf8(std::u16string utf16_string) { std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert; return convert.to_bytes(utf16_string); } Now with VS2015 I get: 1>unicode.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static class std::locale::id std::codecvt<char16_t,char,struct _Mbstatet>::id" (__imp_?id@?$codecvt@_SDU_Mbstatet@@@std@@2V0locale@2@A) 回答1: Old question, but for

Using char16_t and char32_t in I/O

回眸只為那壹抹淺笑 提交于 2019-11-27 14:20:14
C++11 introduces char16_t and char32_t to facilitate working with UTF-16- and UTF-32-encoded text strings. But the <iostream> library still only supports the implementation-defined wchar_t for multi-byte I/O. Why has support for char16_t and char32_t not been added to the <iostream> library to complement the wchar_t support? In the proposal Minimal Unicode support for the standard library (revision 2) it is indicated that there was only support among the Library Working Group for supporting the new character types in strings and codecvt facets. Apparently the majority was opposed to supporing

Using char16_t and char32_t in I/O

荒凉一梦 提交于 2019-11-26 18:23:29
问题 C++11 introduces char16_t and char32_t to facilitate working with UTF-16- and UTF-32-encoded text strings. But the <iostream> library still only supports the implementation-defined wchar_t for multi-byte I/O. Why has support for char16_t and char32_t not been added to the <iostream> library to complement the wchar_t support? 回答1: In the proposal Minimal Unicode support for the standard library (revision 2) it is indicated that there was only support among the Library Working Group for