I need to read files with different encodings. Unicode files are correctly read using开发者_如何学Go
wxFileInputStream fileInputStream(dialog->GetPath());
wxTextInputStream textInputStream(fileInputStream);
If I need to read, say, Cyrillic (cp1251) files, I use:
wxFileInputStream fileInputStream(dialog->GetPath());
wxTextInputStream textInputStream(fileInputStream, " \n", wxCSConv(wxFONTENCODING_CP1251));
But neither of these ways works with both kinds of files. In .NET we can just use:
new StreamReader(file, Encoding.Default)
So what's the alternative of Encoding.Default in wxWidgets or in C++ in general?
Thank you
I believe wxFONTENCODING_SYSTEM would be analogous to Encoding.Default.
The problem was solved by using wxConvAuto(wxFONTENCODING_SYSTEM)
instead of wxCSConv(wxFONTENCODING_SYSTEM)
. The wxConvAuto function first tries to read the file as a Unicode document, and then if it fails, it uses system's encoding to read the ANSI file. It works great!
精彩评论