久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<legend id='Xj7NM'><style id='Xj7NM'><dir id='Xj7NM'><q id='Xj7NM'></q></dir></style></legend>

    • <bdo id='Xj7NM'></bdo><ul id='Xj7NM'></ul>
    <i id='Xj7NM'><tr id='Xj7NM'><dt id='Xj7NM'><q id='Xj7NM'><span id='Xj7NM'><b id='Xj7NM'><form id='Xj7NM'><ins id='Xj7NM'></ins><ul id='Xj7NM'></ul><sub id='Xj7NM'></sub></form><legend id='Xj7NM'></legend><bdo id='Xj7NM'><pre id='Xj7NM'><center id='Xj7NM'></center></pre></bdo></b><th id='Xj7NM'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Xj7NM'><tfoot id='Xj7NM'></tfoot><dl id='Xj7NM'><fieldset id='Xj7NM'></fieldset></dl></div>
      <tfoot id='Xj7NM'></tfoot>

      1. <small id='Xj7NM'></small><noframes id='Xj7NM'>

      2. 什么是“錯"使用 C++ wchar_t 和 wstrings?寬字符有

        What#39;s quot;wrongquot; with C++ wchar_t and wstrings? What are some alternatives to wide characters?(什么是“錯使用 C++ wchar_t 和 wstrings?寬字符有哪些替代方案?)

        <tfoot id='vBdOP'></tfoot>
          <tbody id='vBdOP'></tbody>

          <small id='vBdOP'></small><noframes id='vBdOP'>

        1. <legend id='vBdOP'><style id='vBdOP'><dir id='vBdOP'><q id='vBdOP'></q></dir></style></legend>
                • <bdo id='vBdOP'></bdo><ul id='vBdOP'></ul>
                • <i id='vBdOP'><tr id='vBdOP'><dt id='vBdOP'><q id='vBdOP'><span id='vBdOP'><b id='vBdOP'><form id='vBdOP'><ins id='vBdOP'></ins><ul id='vBdOP'></ul><sub id='vBdOP'></sub></form><legend id='vBdOP'></legend><bdo id='vBdOP'><pre id='vBdOP'><center id='vBdOP'></center></pre></bdo></b><th id='vBdOP'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='vBdOP'><tfoot id='vBdOP'></tfoot><dl id='vBdOP'><fieldset id='vBdOP'></fieldset></dl></div>
                  本文介紹了什么是“錯"使用 C++ wchar_t 和 wstrings?寬字符有哪些替代方案?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我在 C++ 社區中看到很多人(尤其是 freenode 上的##c++)對 wstringswchar_t 的使用以及它們在 windows 中的使用表示不滿接口.wchar_twstring 到底有什么錯誤",如果我想支持國際化,有哪些寬字符的替代方案?

                  I have seen a lot of people in the C++ community(particularly ##c++ on freenode) resent the use of wstrings and wchar_t, and their use in the windows api. What is exactly "wrong" with wchar_t and wstring, and if I want to support internationalization, what are some alternatives to wide characters?

                  推薦答案

                  wchar_t 是什么?

                  wchar_t 的定義使得任何語言環境的 char 編碼都可以轉換為 wchar_t 表示,其中每個 wchar_t 僅表示一個代碼點:

                  What is wchar_t?

                  wchar_t is defined such that any locale's char encoding can be converted to a wchar_t representation where every wchar_t represents exactly one codepoint:

                  類型 wchar_t 是一個獨特的類型,其值可以代表支持的語言環境 (22.3.1) 中指定的最大擴展字符集的所有成員的不同代碼.

                  Type wchar_t is a distinct type whose values can represent distinct codes for all members of the largest extended character set specified among the supported locales (22.3.1).

                                 ;              ;              ;    —C++ [basic.fundamental] 3.9.1/5

                                                                                                 — C++ [basic.fundamental] 3.9.1/5

                  要求 wchar_t 足夠大以同時表示來自所有語言環境的任何字符.也就是說,用于 wchar_t 的編碼可能因地區而異.這意味著您不一定使用一種語言環境將字符串轉換為 wchar_t,然后使用另一種語言環境將其轉換回 char.1

                  This does not require that wchar_t be large enough to represent any character from all locales simultaneously. That is, the encoding used for wchar_t may differ between locales. Which means that you cannot necessarily convert a string to wchar_t using one locale and then convert back to char using another locale.1

                  由于使用 wchar_t 作為所有語言環境之間的通用表示似乎是 wchar_t 在實踐中的主要用途,因此您可能想知道它有什么好處.

                  Since using wchar_t as a common representation between all locales seems to be the primary use for wchar_t in practice you might wonder what it's good for if not that.

                  wchar_t 的最初意圖和目的是通過定義它來簡化文本處理,使其需要從字符串的代碼單元到文本字符的一對一映射,從而允許使用相同的簡單算法as 與 ascii 字符串一起用于其他語言.

                  The original intent and purpose of wchar_t was to make text processing simple by defining it such that it requires a one-to-one mapping from a string's code-units to the text's characters, thus allowing the use of the same simple algorithms as are used with ascii strings to work with other languages.

                  不幸的是,wchar_t 規范的措辭假設字符和代碼點之間存在一對一的映射來實現這一點.Unicode 打破了這個假設2,所以你也不能安全地將 wchar_t 用于簡單的文本算法.

                  Unfortunately the wording of wchar_t's specification assume a one-to-one mapping between characters and codepoints to achieve this. Unicode breaks that assumption2, so you can't safely use wchar_t for simple text algorithms either.

                  這意味著便攜式軟件不能將 wchar_t 用作語言環境之間文本的通用表示,也不能使用簡單的文本算法.

                  This means that portable software cannot use wchar_t either as a common representation for text between locales, or to enable the use of simple text algorithms.

                  不管怎樣,對于可移植代碼來說并不多.如果定義了 __STDC_ISO_10646__,則 wchar_t 的值直接表示在所有語言環境中具有相同值的 Unicode 代碼點.這使得進行前面提到的區域間轉換是安全的.但是,您不能僅僅依靠它來決定您可以以這種方式使用 wchar_t,因為盡管大多數 unix 平臺都定義了它,但即使 Windows 在所有語言環境中使用相同的 wchar_t 語言環境,Windows 也不會這樣做.

                  Not much, for portable code anyway. If __STDC_ISO_10646__ is defined then values of wchar_t directly represent Unicode codepoints with the same values in all locales. That makes it safe to do the inter-locale conversions mentioned earlier. However you can't rely only on it to decide that you can use wchar_t this way because, while most unix platforms define it, Windows does not even though Windows uses the same wchar_t locale in all locales.

                  Windows 沒有定義 __STDC_ISO_10646__ 的原因是因為 Windows 使用 UTF-16 作為其 wchar_t 編碼,并且因為 UTF-16 使用代理對來表示大于 U+FFFF 的代碼點,這意味著UTF-16 不滿足 __STDC_ISO_10646__ 的要求.

                  The reason Windows doesn't define __STDC_ISO_10646__ is because Windows use UTF-16 as its wchar_t encoding, and because UTF-16 uses surrogate pairs to represent codepoints greater than U+FFFF, which means that UTF-16 doesn't satisfy the requirements for __STDC_ISO_10646__.

                  對于平臺特定的代碼 wchar_t 可能更有用.它本質上在 Windows 上是必需的(例如,某些文件在不使用 wchar_t 文件名的情況下根本無法打開),盡管據我所知,Windows 是唯一的平臺(所以也許我們可以將 wchar_t 視為Windows_char_t").

                  For platform specific code wchar_t may be more useful. It's essentially required on Windows (e.g., some files simply cannot be opened without using wchar_t filenames), though Windows is the only platform where this is true as far as I know (so maybe we can think of wchar_t as 'Windows_char_t').

                  事后看來,wchar_t 顯然對于簡化文本處理或作為獨立于語言環境的文本的存儲沒有用處.可移植代碼不應試圖將其用于這些目的.非可移植代碼可能僅僅因為某些 API 需要它而發現它很有用.

                  In hindsight wchar_t is clearly not useful for simplifying text handling, or as storage for locale independent text. Portable code should not attempt to use it for these purposes. Non-portable code may find it useful simply because some API requires it.

                  我喜歡的替代方法是使用 UTF-8 編碼的 C 字符串,即使在對 UTF-8 不是特別友好的平臺上也是如此.

                  The alternative I like is to use UTF-8 encoded C strings, even on platforms not particularly friendly toward UTF-8.

                  通過這種方式,人們可以使用跨平臺的通用文本表示編寫可移植代碼,將標準數據類型用于其預期目的,獲得語言對這些類型的支持(例如字符串文字,盡管需要一些技巧才能使其適用于某些編譯器)、一些標準庫支持、調試器支持(可能需要更多技巧)等.使用寬字符通常更難或不可能獲得所有這些,并且您可能會在不同平臺上獲得不同的部分.

                  This way one can write portable code using a common text representation across platforms, use standard datatypes for their intended purpose, get the language's support for those types (e.g. string literals, though some tricks are necessary to make it work for some compilers), some standard library support, debugger support (more tricks may be necessary), etc. With wide characters it's generally harder or impossible to get all of this, and you may get different pieces on different platforms.

                  UTF-8 沒有提供的一件事是能夠使用簡單的文本算法,例如 ASCII.在這方面 UTF-8 并不比任何其他 Unicode 編碼差.事實上,它可能被認為更好,因為 UTF-8 中的多代碼單元表示更常見,因此與嘗試堅持使用 UTF 相比,處理此類可變寬度字符表示的代碼中的錯誤更有可能被注意到和修復-32 使用 NFC 或 NFKC.

                  One thing UTF-8 does not provide is the ability to use simple text algorithms such as are possible with ASCII. In this UTF-8 is no worse than any other Unicode encoding. In fact it may be considered to be better because multi-code unit representations in UTF-8 are more common and so bugs in code handling such variable width representations of characters are more likely to be noticed and fixed than if you try to stick to UTF-32 with NFC or NFKC.

                  許多平臺使用 UTF-8 作為其原生字符編碼,并且許多程序不需要任何重要的文本處理,因此在這些平臺上編寫國際化程序與不考慮國際化編寫代碼幾乎沒有什么不同.編寫更廣泛可移植的代碼,或在其他平臺上編寫,需要在使用其他編碼的 API 邊界插入轉換.

                  Many platforms use UTF-8 as their native char encoding and many programs do not require any significant text processing, and so writing an internationalized program on those platforms is little different from writing code without considering internationalization. Writing more widely portable code, or writing on other platforms requires inserting conversions at the boundaries of APIs that use other encodings.

                  某些軟件使用的另一種替代方法是選擇跨平臺表示,例如保存 UTF-16 數據的無符號短數組,然后提供所有庫支持并簡單地承擔語言支持等方面的成本.

                  Another alternative used by some software is to choose a cross-platform representation, such as unsigned short arrays holding UTF-16 data, and then to supply all the library support and simply live with the costs in language support, etc.

                  C++11 添加了新的寬字符作為 wchar_t、char16_t 和 char32_t 的替代品,并具有附帶的語言/庫功能.這些實際上并不能保證是 UTF-16 和 UTF-32,但我不認為任何主要實現會使用其他任何東西.C++11 還改進了 UTF-8 支持,例如使用 UTF-8 字符串文字,因此沒有必要欺騙 VC++ 生成 UTF-8 編碼的字符串(盡管我可能會繼續這樣做而不是使用 u8 前綴).

                  C++11 adds new kinds of wide characters as alternatives to wchar_t, char16_t and char32_t with attendant language/library features. These aren't actually guaranteed to be UTF-16 and UTF-32, but I don't imagine any major implementation will use anything else. C++11 also improves UTF-8 support, for example with UTF-8 string literals so it won't be necessary to trick VC++ into producing UTF-8 encoded strings (although I may continue to do so rather than use the u8 prefix).

                  TCHAR:TCHAR 用于遷移舊的 Windows 程序,這些程序采用從 char 到 wchar_t 的傳統編碼,最好忘記,除非您的程序是在前一千年編寫的.它不是可移植的,并且其編碼甚至其數據類型本質上都是不確定的,因此無法與任何基于非 TCHAR 的 API 一起使用.由于它的目的是遷移到 wchar_t,我們在上面看到這不是一個好主意,因此使用 TCHAR 沒有任何價值.

                  TCHAR: TCHAR is for migrating ancient Windows programs that assume legacy encodings from char to wchar_t, and is best forgotten unless your program was written in some previous millennium. It's not portable and is inherently unspecific about its encoding and even its data type, making it unusable with any non-TCHAR based API. Since its purpose is migration to wchar_t, which we've seen above isn't a good idea, there is no value whatsoever in using TCHAR.

                  <子>1.可以在 wchar_t 字符串中表示但在任何語言環境中都不支持的字符不需要用單個 wchar_t 值表示.這意味著 wchar_t 可以對某些字符使用可變寬度編碼,這又明顯違反了 wchar_t 的意圖.盡管 wchar_t 可表示的字符足以說明語言環境支持"該字符是有爭議的,但在這種情況下,可變寬度編碼是不合法的,并且 Window 對 UTF-16 的使用不符合規范.

                  2.Unicode 允許用多個代碼點表示許多字符,這對于簡單的文本算法與可變寬度編碼產生了相同的問題.即使嚴格維護組合規范化,某些字符仍然需要多個代碼點.請參閱:http://www.unicode.org/standard/where/

                  這篇關于什么是“錯"使用 C++ wchar_t 和 wstrings?寬字符有哪些替代方案?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  In what ways do C++ exceptions slow down code when there are no exceptions thown?(當沒有異常時,C++ 異常會以何種方式減慢代碼速度?)
                  Why catch an exception as reference-to-const?(為什么要捕獲異常作為對 const 的引用?)
                  When and how should I use exception handling?(我應該何時以及如何使用異常處理?)
                  Scope of exception object in C++(C++中異常對象的范圍)
                  Catching exceptions from a constructor#39;s initializer list(從構造函數的初始化列表中捕獲異常)
                  Difference between C++03 throw() specifier C++11 noexcept(C++03 throw() 說明符 C++11 noexcept 之間的區別)
                • <legend id='qyCPN'><style id='qyCPN'><dir id='qyCPN'><q id='qyCPN'></q></dir></style></legend>

                      <tfoot id='qyCPN'></tfoot>
                          <tbody id='qyCPN'></tbody>
                      1. <i id='qyCPN'><tr id='qyCPN'><dt id='qyCPN'><q id='qyCPN'><span id='qyCPN'><b id='qyCPN'><form id='qyCPN'><ins id='qyCPN'></ins><ul id='qyCPN'></ul><sub id='qyCPN'></sub></form><legend id='qyCPN'></legend><bdo id='qyCPN'><pre id='qyCPN'><center id='qyCPN'></center></pre></bdo></b><th id='qyCPN'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='qyCPN'><tfoot id='qyCPN'></tfoot><dl id='qyCPN'><fieldset id='qyCPN'></fieldset></dl></div>

                          <bdo id='qyCPN'></bdo><ul id='qyCPN'></ul>

                          <small id='qyCPN'></small><noframes id='qyCPN'>

                            主站蜘蛛池模板: 日韩av免费看| www日本在线 | 国产日韩欧美二区 | 成年免费大片黄在线观看一级 | 99在线精品视频 | 一区二区三区在线看 | 国产一级淫片免费视频 | 亚洲一区二区三区免费在线观看 | 成人不卡视频 | 在线观看黄色电影 | 国产一区二区免费 | 久久性色| 成年人免费看 | 久久久久久成人 | 伦理二区 | 97高清国语自产拍 | 亚洲精品9999久久久久 | 91精品国产99| 91天堂网| 久久国产一区二区三区 | 久久新视频 | 国产成人jvid在线播放 | 五月精品视频 | 亚洲视频二区 | 亚洲综合色自拍一区 | 久久久久久亚洲 | 日韩精品一区二区三区中文在线 | 亚洲三区在线播放 | 九九福利 | 欧美成人一区二区三区 | 草久久| 综合精品 | www.天堂av.com| 精品1区2区 | 欧美日韩精品国产 | 求个av网址 | 国产精品久久国产愉拍 | 国产婷婷在线视频 | h在线看| 欧美精品欧美精品系列 | www.国产精品|