Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Unicode version of ifstream class ?

Posted on 1997-06-19
5
1,486 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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.

856 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