Yuan Yijun (bbbush) wrote,
Yuan Yijun

wstream 真有名堂

当初看 STL 有三分之一都是讲 locale 的,那本书看完了都云里雾里。刚才碰到了问题,搜索了一把。


locale 分成不同的 facet,可以构建自己的 locale。用 ws.imbue(loc) 设置一个流的 locale。如果要将字符串转码,或者防止被错误地转码,就应当设置 locale 先。

防止被错误地转码,比如在保存文件时,wofstream 默认是把字符转成单字节的,要是遇到没法转的字符就停掉了。据说要换用一个不做任何转换的 facet 才可以保存原样的信息。

看到一段用来转换 UCS4 和 UTF-8 的代码,说 Boost 里面提供了各种各样的 facet。
Tags: 工作

  • My tweets

    Wed, 09:34: WIthout threading support, Outlook managed to introduce "Focused" and "Other" as tabs in the inbox. Now I got two inbox to check.

  • My tweets

    Tue, 11:06: With IntelliJ IDEA it is really hard to tell which window is "active" by looking at the taskbar icon. The project n……

  • My tweets

    Sun, 21:01: Scared a little bit https://t.co/MQI4IPzfDa Sun, 22:07: https://t.co/22J8hD4xrp ugly paradise

  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded