Solved

Problems with C++ fstream class and Unicode

Posted on 1998-05-14
11
909 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
[X]
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
  • 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
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!

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
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 learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

707 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