Solved

Unicode version of ifstream class ?

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Cell Value from TStringGrid::StringGrid1DrawColumnCell function in C++ builder XE8 3 82
C++ question 3 65
Exception thrown at 0x00007FFD5BC81F28 7 44
What is sub-make ? 2 60
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

773 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