zoukankan      html  css  js  c++  java
  • C++ string在unicode下

    VS2008编译环境下
    string 不管是在unicode还是多字节字符集下。都是单字节,数字字母占一个字节,汉字占2个字节。如果想用宽字符 请用std::wstring,这个和THCAR的效果相同。当然也可以用微软的CString更方便些。

    I have written before about How to use Unicode with Python, but I've never figured out how to use Unicode in Standard C before. I managed to find an extremely helpful UTF-8 and Unicode FAQ which answers most of the questions, particularly the section beginning with C Support for Unicode and UTF-8. Additionally, Tim Bray's Characters vs. Bytes provides a very readable overview of Unicode encodings.

    The good news is that if you use wchar_t* strings and the family of functions related to them such as wprintf, wcslen, and wcslcat, you are dealing with Unicode values. In the C++ world, you can use std::wstring to provide a friendly interface. My only complaint is that these are 32-bit (4 byte) characters, so they are memory hogs for all languages. The reason for this choice is that it guarantees each possible character can be represented by one value. Contrary to popular belief, it is possible for a Unicode character to require multiple 16-bit values. While these characters are rare, it is dangerous to hard code that belief into your software, particularly as computers spread through more of the world, and as people create new characters.

  • 相关阅读:
    设置ActiveMQ的访问密码
    Java NIO SocketChannel套接字通道
    Java 8 基础API的一些小的该进
    Java 8 异常该进
    Java NIO Channel to Channel Transfers通道传输接口
    Java NIO Scatter / Gather
    mysql分表经验总结
    Java 8 Optional类深度解析(转)
    Java 8 文件操作(转)
    使用 Java8 Optional 的正确姿势(转)
  • 原文地址:https://www.cnblogs.com/yuzhould/p/4454995.html
Copyright © 2011-2022 走看看