You use wchar_t
because you're reading the file using wifstream
; if you were reading using ifstream
you'd use char
, and similarly for char16_t
and char32_t
.
Assuming (as the example does) that wchar_t
is 32-bit, and that the native character set that it represents is UTF-32 (UCS-4), then this is the simplest way to read a file as UTF-32; it is presented as such in the example for contrast to reading a file as UTF-16. A more portable method would be to use basic_ifstream<char32_t>
and std::codecvt_utf8<char32_t>
explicitly, as this is guaranteed to convert from a UTF-8 input stream to UTF-32 elements.