how do I know whether .txt file is of char or wchar_t type?

R

r.z.

I know I'm missing something and maybe someone will shed some light on this:
I just wan't to read some info from a text file I create in Notepad. What
should I use:
basic_ifstream<char, char_traits<char>> file(filepath)
or
basic_ifstream<wchar_t, char_traits<wchar_t>> file(filepath)

I surround all strings with TEXT macro in my program but how to know what is
the type data stored in an external file ?
 
B

blytkerchan

r.z. said:
I know I'm missing something and maybe someone will shed some light on this:
I just wan't to read some info from a text file I create in Notepad. What
should I use:
basic_ifstream<char, char_traits<char>> file(filepath)
or
basic_ifstream<wchar_t, char_traits<wchar_t>> file(filepath)

I surround all strings with TEXT macro in my program but how to know what is
the type data stored in an external file ?
Open the file, read a few bytes, try to "sniff" it. UTF-16, for
example, will give you a nul-character for every two characters most of
the time. UTF-8 might give you a byte-order mark (but might not), etc.
There's no magic way to do this, but if you look at such open-source
projects as GNU file, Xerces-C, etc. which all deal with the same kind
of problems, the methods are basically always the same.

rlc
 
R

r.z.

thanks

blytkerchan said:
Open the file, read a few bytes, try to "sniff" it. UTF-16, for
example, will give you a nul-character for every two characters most of
the time. UTF-8 might give you a byte-order mark (but might not), etc.
There's no magic way to do this, but if you look at such open-source
projects as GNU file, Xerces-C, etc. which all deal with the same kind
of problems, the methods are basically always the same.

rlc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top