Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Locale/UTF-8 fi...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 43163 of 47561
Post > Topic >>

Locale/UTF-8 file path with std::ifstream

by "mpalomas@[EMAIL PROTECTED] " <mpalomas@[EMAIL PROTECTED] > Feb 8, 2008 at 01:16 AM

Hi C++ folks,

I have trouble to open files whose path contains non-ascii characters
with std::ifstream.
For instance let's say i just have a file which has Japanese
characters either in the file path or the file name :
=E7=96=91=E5=95=8F.dat=
 . The
file itself does not contains unicode characters or whatever, it is a
binary file, but the file name, or path, contains non-ascii
characters, here it is Japanese but it could be anything else, i know
nothing about my customers languages.

On Linux, simply doing this :
std::ifstream ifs('=E7=96=91=E5=95=8F.dat"); just works, i can open the
file=
.. Of
course in my app file path are not hard coded in the source code, the
user choose his file using a file dialog. The file dialog returns me a
QString (Trolltech Qt framework). If the returned QString is named
filepath, then std::ifstream ifs(filepath.toUtf8()) works fine too.

The problem is my application is cross-platform, and on Windows XP the
2 above pieces of code does not work at all ! The ifstream fails to
open the file ... I suspect this is a locale issue, i just know my
Linux distribution uses UTF-8 by default, this must be why it works,
whereas on Windows, it seems strange, ifstream.getloc().name() returns
just "C" , and if i create a default locale with std::locale
my_locale("") , then my_locale.name() returns French_France.1252 ...

I'm stuck with all this locale/encoding problems, it is not clear in
my mind, to solve a problem firstly you need to understand the
problem, and i think i don't :-) I wonder if i have to change the
locale on Windows to a UTF-8 one (i didn't succeed), if i have to use
some conversion functions, or wifstream, or wstring, even after
searching on Google i didn't made any progress, internationalization
stuff does not seem to be trivial with C++ .

Any help, hint, or suggestion would be appreciated !

Regards,

Micha=C3=ABl
 




 3 Posts in Topic:
Locale/UTF-8 file path with std::ifstream
"mpalomas@[EMAIL PRO  2008-02-08 01:16:44 
Re: Locale/UTF-8 file path with std::ifstream
"Daniel T." <  2008-02-08 07:32:31 
Re: Locale/UTF-8 file path with std::ifstream
"mpalomas@[EMAIL PRO  2008-02-08 05:28:24 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Sep 7 4:11:11 CDT 2008.