Question

I'm having troubles opening a Unicode file in C++ using fstreams instead of the older FILE-based file handling functions. When opening a file using _wfopen, I can specify a mode to tell it what character encoding to use. Eg:

_wfopen_s(&file, fileName, unicode ? L"r+, ccs=UTF-16LE" : L"r+" );

This works fine. When using wifstream though, I get both the byte-order mark at the beginning of the file, and the rest of the file appears in memory interlaced with 0x00. Clearly it's just reading in each character as a byte.

My question is: is there any equivalent to the 'mode' parameter above for use with fstreams? It's not terrible if there isn't, I just prefer the syntax of streams over FILEs.

Thanks!

Was it helpful?

Solution

You could try setting using a conversion facet for the stream. Check the files codecvt.h and codecvt.cpp as an example.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top