How to write a std::string to a UTF-8 text file

前端 未结 9 1182
盖世英雄少女心
盖世英雄少女心 2020-12-01 01:04

I just want to write some few simple lines to a text file in C++, but I want them to be encoded in UTF-8. What is the easiest and simple way to do so?

9条回答
  •  爱一瞬间的悲伤
    2020-12-01 01:46

    As to UTF-8 is multibite characters string and so you get some problems to work and it's a bad idea/ Instead use normal Unicode.

    So by my opinion best is use ordinary ASCII char text with some codding set. Need to use Unicode if you use more than 2 sets of different symbols (languages) in single.

    It's rather rare case. In most cases enough 2 sets of symbols. For this common case use ASCII chars, not Unicode.

    Effect of using multibute chars like UTF-8 you get only China traditional, arabic or some hieroglyphic text. It's very very rare case!!!

    I don't think there are many peoples needs that. So never use UTF-8!!! It's avoid strong headache of manipulate such strings.

提交回复
热议问题