Using streams for opening files in unicode.

G

gangs

I need to know how can I open a file which is named using UTF-16
encoding in unicode. I am desperately trying to open the file using the
wofstream typedef, but even it takes the parameter as const char*, I
tried converting the filename from UTF16 to UTF8 encoding, wofstream
does not seem to work with that.
What I gather is that streams internally use fopen for opening up a
file, I could not find any way for passing a file descriptor to the
stream class to initialize it, basically trying to use a _wfopen to get
a file descriptor, but how can I pass it to a stream to initialize it
to it?

Kindly Note: I have to use streams for the same, it is a restriction in
the current architecture.

Please do let me know of any other way .

Gangs.
 
?

=?iso-8859-1?q?Kirit_S=E6lensminde?=

gangs said:
I need to know how can I open a file which is named using UTF-16
encoding in unicode. I am desperately trying to open the file using the
wofstream typedef, but even it takes the parameter as const char*, I
tried converting the filename from UTF16 to UTF8 encoding, wofstream
does not seem to work with that.
What I gather is that streams internally use fopen for opening up a
file, I could not find any way for passing a file descriptor to the
stream class to initialize it, basically trying to use a _wfopen to get
a file descriptor, but how can I pass it to a stream to initialize it
to it?

Kindly Note: I have to use streams for the same, it is a restriction in
the current architecture.

There isn't any simple way of doing this. You need to convert the
UTF-16 sequence into the correct code page that the application is
running. This code page may not of course be able to handle the
characters at all in which case opening the file is going to be hard.

If you have OS specific ways of getting a lower level file handle then
you could write your own IO stream buffer. It's not as hard as it may
at first seem.

I'm guessing that you're doing this on Windows. If you are, and you do
write your own stream classes that can handle full Windows file names
then please release the implementation - I'm sure many people would be
interested in it (including me). I'll swap you our TCP/IP stream
classes :)


K
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top