Unicode File I/O
-
I've been trying to use std::wifstream to read a unicode file, like so (in a project with UNICODE on): std::wifstream wf; wchar_t wch; wf.open("unicode.txt"); while(wf.get(wch)) { std::wcout << wch; } wf.close(); Funny thing is, this *still* reads the file byte by byte, NOT wchar_t by wchar_t. This means that if you had a 000D in the file, you'd get a 00 followed by a 0D, NOT a 0D as you'd expect. On the other hand, using the C style FILE* does work properly, as: FILE* fp = _wfopen(L"unicode.txt", L"r+b"); wchar_t wch; while(!feof(fp)) { wch = fgetwc(fp); std::wcout << wch; } fcloseall(); The above code accomplishes what I want. However, as I am not too keen on using just C or Win32 functions, can someone shed somelight on what's going on? Thanks in advance, Shanker.
-
I've been trying to use std::wifstream to read a unicode file, like so (in a project with UNICODE on): std::wifstream wf; wchar_t wch; wf.open("unicode.txt"); while(wf.get(wch)) { std::wcout << wch; } wf.close(); Funny thing is, this *still* reads the file byte by byte, NOT wchar_t by wchar_t. This means that if you had a 000D in the file, you'd get a 00 followed by a 0D, NOT a 0D as you'd expect. On the other hand, using the C style FILE* does work properly, as: FILE* fp = _wfopen(L"unicode.txt", L"r+b"); wchar_t wch; while(!feof(fp)) { wch = fgetwc(fp); std::wcout << wch; } fcloseall(); The above code accomplishes what I want. However, as I am not too keen on using just C or Win32 functions, can someone shed somelight on what's going on? Thanks in advance, Shanker.
i always use the CreatFile() ... ReadFile() ... stuff to read the file in as raw data and then convert to unicode (cast a pointer to it as a _TCHAR*) works for me :) --- "every year we invent better idiot proof systems and every year they invent better idiots"