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

前端 未结 9 1177
盖世英雄少女心
盖世英雄少女心 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:44

    Use Glib::ustring from glibmm.

    It is the only widespread UTF-8 string container (AFAIK). While glyph (not byte) based, it has the same method signatures as std::string so the port should be simple search and replace (just make sure that your data is valid UTF-8 before loading it into a ustring).

提交回复
热议问题