[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 924
  • Last Modified:

Problems with C++ fstream class and Unicode

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
sector
Asked:
sector
  • 6
  • 5
1 Solution
 
RONSLOWCommented:
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
 
mikeblasCommented:
It's istream::getline that works only with char; wistream::getline (and all of its members!) work fine with wchar.

.B ekiM

0
 
mikeblasCommented:
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
RONSLOWCommented:
It's the same class; it's just a different template expansion.

.B ekiM

0
 
mikeblasCommented:
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
 
RONSLOWCommented:
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
 
mikeblasCommented:
which file do i have to inlcude in order to make the wistream
be succesfully compiled ???

0
 
RONSLOWCommented:
"have members with the same names" is meaningless in C++, because C++ provides for overloading.

Indeed, wistream comes from <istream>.

.B ekiM


0
 
mikeblasCommented:
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
 
RONSLOWCommented:
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
 
RONSLOWCommented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now