does (w)ifstream support different encodings

前端 未结 3 1644
粉色の甜心
粉色の甜心 2020-11-30 08:18

When I read a text file to a wide character string (std::wstring) using an wifstream, does the stream implementation support different encodings - i.e. can it be used to rea

3条回答
  •  天涯浪人
    2020-11-30 08:27

    ifstream does not care about encoding of file. It just reads chars(bytes) from file. wifstream reads wide bytes(wchar_t), but it still doesn't know anything about file encoding. wifstream is good enough for UCS-2 — fixed-length character encoding for Unicode (each character represented with two bytes).

    You could use IBM ICU library to deal with Unicode files.

    The International Component for Unicode (ICU) is a mature, portable set of C/C++ and Java libraries for Unicode support, software internationalization (I18N) and globalization (G11N), giving applications the same results on all platforms.

    ICU is released under a nonrestrictive open source license that is suitable for use with both commercial software and with other open source or free software.

提交回复
热议问题