Solved

Unicode version of ifstream class ?

Posted on 1997-06-19
5
1,477 Views
Last Modified: 2013-12-14
Where can I get a Unicode equivalent to the ifstream
class (ie. using TCHAR) ?

I am using Microsoft Visual C++ 4.2
0
Comment
Question by:mongo061997
  • 3
  • 2
5 Comments
 

Author Comment

by:mongo061997
ID: 1163977
Edited text of question
0
 
LVL 4

Accepted Solution

by:
md041797 earned 100 total points
ID: 1163978
Just write an inserter and an extractor for your data type.

ostream &operator << (const TCHAR *c, ostream &out) {
    out << wstrlen (c)+1;
    out.write ((const char *)c, wstrlen (c)+1);
    return out;
    }

ostream &operator << (const TCHAR c, ostream &out) {
    out.write ((const char *)&c, sizeof (TCHAR));
    return out;
    }

istream &operator >> (TCHAR *c, istream &in) {
    int length;
    in >> length;
    in.read ((char *)c, length);
    return in;
    }

istream &operator >> (TCHAR c, istream &in) {
    in.read ((char *)&c, sizeof (TCHAR));
    return in;
    }



0
 

Author Comment

by:mongo061997
ID: 1163979
Thank you, md.
The answer was technically good, but it needs adaptation
for IFSTREAM.
0
 

Author Comment

by:mongo061997
ID: 1163980
Thank you, md.
The answer was very interesting, but I will need to adapt it
for IFSTREAM.
0
 
LVL 4

Expert Comment

by:md041797
ID: 1163981
Since ifstream is derived from istream, these extractors will work as advertised.  The complier will cast the ifstream to istream automatically, so you can write:

ifstream in;
WCHAR UniChar;
in >> UniChar;
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now