Take the 2-minute tour ×

I need to read files with different encodings. Unicode files are correctly read using

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

share|improve this question
add comment

2 Answers

I believe wxFONTENCODING_SYSTEM would be analogous to Encoding.Default.

share|improve this answer
Nope, that didn't work. –  Alex May 10 '11 at 14:15
wxFONTENCODING_SYSTEM works with non Unicode files. –  Alex May 10 '11 at 15:39
@Alex, I believe that Encoding.Default only "works" because MS is playing with the data. See the big warning message here: msdn.microsoft.com/en-us/library/…. wxWidgets is probably playing it safer, see here: docs.wxwidgets.org/trunk/… –  Mark May 10 '11 at 16:37
I solved the problem by using wxConvAuto function. –  Alex May 11 '11 at 6:46
add comment
up vote 0 down vote accepted

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!

share|improve this answer
add comment

Your Answer


