By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,121 Members | 1,064 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,121 IT Pros & Developers. It's quick & easy.

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

P: n/a
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 ?
Dec 27 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
r.z. wrote:
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

Dec 27 '06 #2

P: n/a
thanks

"blytkerchan" <bl*********@gmail.comwrote in message
news:11**********************@73g2000cwn.googlegro ups.com...
r.z. wrote:
>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

Dec 27 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.