Solved

Problems with C++ fstream class and Unicode

Posted on 1998-05-14
11
893 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
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.

 
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
 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

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