Solved

Problems with C++ fstream class and Unicode

Posted on 1998-05-14
11
873 Views
Last Modified: 2013-12-14
i am tring to get a line from a file with the fstream class
and with the getline command + working with UNICODE
and i get the following error :
 
class istream &istream::getline(char *,int,char)' : cannot convert parameter 1 from 'unsigned short [260]' to 'char *'

and the oroginal line looks liek this :

        char line[MAX_PATH];
             .....
      input.getline(line,260);
0
Comment
Question by:sector
  • 6
  • 5
11 Comments
 
LVL 10

Accepted Solution

by:
RONSLOW earned 200 total points
ID: 1177343
UNICODE uses wide characters (effectively shorts).  getline ONLY works with chars.

Try using the Win32 API functions for reading/writing files instead of C++ streams (or if you are using MFC use CStdioFile or other CFile derivative).

0
 
LVL 11

Expert Comment

by:mikeblas
ID: 1177344
It's istream::getline that works only with char; wistream::getline (and all of its members!) work fine with wchar.

.B ekiM

0
 
LVL 11

Expert Comment

by:mikeblas
ID: 1177345
Please reject my answer and accept that from Mike.

I'd forgotten about wistream.  I was looking for istream functions that handled wide chars .. didn't think of a different stream class altogether.  Guess that comes from not using UNICODE enough :-(

0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1177346
It's the same class; it's just a different template expansion.

.B ekiM

0
 
LVL 11

Expert Comment

by:mikeblas
ID: 1177347
You mean a different class expanded from the same template class.

Individual instantiations of a template class result in separate classes that have the same members and base classes.  Just as if they had been written separately.  If the template class does not specify a base class, then they are not even siblings.

In this case, both istream and wistrem are expansions of the template class basic_istream, specialized for elements of type char or wchar_t respectively.

Please consider your nits picked :-)

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 10

Expert Comment

by:RONSLOW
ID: 1177348
If they had the same members, then getline() would've worked on a wchar* even if you were using istream instead of wistream.

Wouldn't it?

.B ekiM
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 1177349
which file do i have to inlcude in order to make the wistream
be succesfully compiled ???

0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1177351
"have members with the same names" is meaningless in C++, because C++ provides for overloading.

Indeed, wistream comes from <istream>.

.B ekiM


0
 
LVL 11

Expert Comment

by:mikeblas
ID: 1177352
Eh?  What is meaningless about saying that one class has (all) members with the same names as another class.  That is what a template expansion will result in (I'll pick my own nits here .. the names of constructors and destructors are probably not the same once expanded .. I'm not sure of that).

Distinct template class expansions result in similar, but distinct, classes.  They aren't the same class .. they have separate RTTI etc.  And they are not even sibling classes, unless the template class specifies them as having the same base class (indeed, if there is no base class in the template, then the two classes are unrelated from an inheritance point of view).

Gees those nits are biting around here lately .. must be the time of year :-)

0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1177353
BTW, ilanmoshe .. you still haven't rejected my prposed answer.  The points should go to MikeB.

And thanks Mike (seriously) for pointing out the error of my ways .. I know I've (tried) to do the same for you before :-)

0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1177354
RONSLOW has requested that I award points to mikeblas for his help on this question.
Please see the question directed to you in this topic area mikeblas.

Linda Gardner
Customer Service @ Experts Exchange
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

757 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

20 Experts available now in Live!

Get 1:1 Help Now