FStream Read and write Unicode files

Source: Internet
Author: User

Today encountered to deal with the Unicode file situation, the Internet to find a lap is read out of bytes, and then turn, this inconvenient Ah! Think of a codecvt such a thing, the clues, found the method.

Locale Utf16 (""), new codecvt_utf16<wchar_t, 0X10FFFF, little_endian>); Wifstream fin ("module.rc"); Wofstream fout ("Module.rc.tt", Ios_base::out | ios_base::binary); Fin.imbue (UTF16); Fout.imbue (UTF16); wstring Line; while (Getline (Fin, line)) Fout << line << Endl;

  

Codecvt_utf16 the last parameter I use is Little_endian, because my file is this format, people according to their own situation to modify. If you simply read the content, you can use Consume_header to automatically identify the format.

Wofstream need to use binary output, otherwise the output of the back is garbled.

FStream Read and write Unicode files

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.