[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Problems with C++ fstream class and Unicode

Posted on 1998-05-14
11
Medium Priority
?
919 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 400 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
Independent Software Vendors: 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

Independent Software Vendors: 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!

Question has a verified solution.

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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 …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
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.
Suggested Courses

649 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