473,397 Members | 2,116 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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

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
2 1767
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Bren | last post by:
Hi all, I wonder if anyone knows of a string class out there that can do on demand conversion from wchar_t to char? We are writing an app that will need to be localized and cross platform. ...
1
by: Mark A. Gibbs | last post by:
Good day, I'm asking this just out of curiosity, but it just occurred to me to reread the section on wchar_t (3.9.1.5), and unless I'm reading it wrong, there is no guarantee that wchar_t is...
5
by: Jamie | last post by:
I have a file that was written using Java and the file has unicode strings. What is the best way to deal with these in C? The file definition reads: Data Field Description CHAR File...
15
by: Yifan | last post by:
Hi Does anybody know how to convert System::String* to char*? I searched the System::String class members and did not find any. Thanks Yifan
2
by: starffly | last post by:
I want to read a xml file in Unicode, UTF-8 or a native encoding into a wchar_t type string, so i write a routine as follows, however, sometimes a Unicode file including Chinese character cannot...
6
by: MattWilson.6185 | last post by:
Hello! I am trying to convert a char * to a LPWSTR, and I am going absolutly mad! I can't find anything besides typle L"string" Unfortunetaly I can't use that... basicaly the setup is ...
33
by: Michael B Allen | last post by:
Hello, Early on I decided that all text (what most people call "strings" ) in my code would be unsigned char *. The reasoning is that the elements of these arrays are decidedly not signed. In...
16
by: Michael Brennan | last post by:
I guess this question only applies to programming applications for UNIX, Windows and similiar. If one develops something for an embedded system I can understand that wchar_t would be unnecessary. ...
5
by: Samant.Trupti | last post by:
Hi, There is one thing I am cofused about.... If I have a declareation say char str; Now if I want to change it to wchar so do I have to change it like .... wchar_t str; or double the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.