?
Solved

ofstream in UNICODE

Posted on 1999-11-26
3
Medium Priority
?
1,294 Views
Last Modified: 2008-03-17
I am porting some code to UNICODE.

The compiler doesn't like:

CString xxx;
xxx.Fomat(_T("Log.txt"));
ofstream fileOutput(xxx);

with error:

'__thiscall ofstream::ofstream(const char *,int,int)' : cannot convert parameter 1 from 'class CString' to 'const char *'


The code is fine in non-UNICODE.

Any ideas?
0
Comment
Question by:simonsmi
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 150 total points
ID: 2236239
'ofstream' has no UNICODE-aware constructor, so attempting to use it with UNICODE strings is futile. Even

ofstream fileOutput( ( LPCTSTR) xxx);

will cause problems.

Use 'CFile' instead...
0
 

Author Comment

by:simonsmi
ID: 2236666
I thought there was a push for people to use the standard C++ language? Are there many other parts of it non-UNICODE compatible?
0
 
LVL 86

Expert Comment

by:jkr
ID: 2236700
>>Are there many other parts of it non-UNICODE compatible?

Well, there are several (though I can't name them, as I only keep in mind the compatible ones ;-)

But as UNICODE support for the 'mainstream' OSs is limited to NT nowadays, I tend to use the Win32 UNICODE APIs when I have to deal with that character set...
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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 how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

601 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