Yuan Yijun (bbbush) wrote,
Yuan Yijun
bbbush

wstream 真有名堂

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

http://www.codeproject.com/vcpp/stl/upgradingstlappstounicode.asp

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

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

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

  • 2020

    Last time I wrote a review was in 2018, about 2017. Or maybe I wrote something elsewhere, maybe on Twitter? It was hard to write something freely…

  • Yoga

    Yesterday JY learned a lot about Yoga poses. I keep saying that as "yogurt", no idea why. - Child's pose. Surprisingly hard for me! - Triangle -…

  • 坏人

    Jimmy had an obsession about bad guys. He wanted to be a bad guy in his star of the week report. He even wanted to live with bad guys. Then he asked…

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments