How do I write a std::codecvt facet?

前端 未结 2 1019
死守一世寂寞
死守一世寂寞 2020-12-16 15:27

How do I write a std::codecvt facet? I\'d like to write ones that go from UTF-16 to UTF-8, which go from UTF-16 to the systems current code page (windows, so CP_ACP), and to

2条回答
  •  隐瞒了意图╮
    2020-12-16 16:07

    The problem with this std::codecvt is it's a solution looking for a problem. Or rather, the problem it's trying to solve is unsolvable, so anybody trying to use it as a solution is going to be very disappointed.

    If you don't know which character set your input or output is, then std::codecvt isn't ever going to be able to help you. Conversely, if you do know which character sets you're using, then you can trivially convert between them with a single function call. Wrapping that function call in a complicated mess of templates doesn't change those fundamentals.

    ...and that's why nobody uses std::codecvt. I recommend you just do what everybody else does, and pretend it never happened.

提交回复
热议问题