-
September 22nd, 2012, 05:51 PM
#1
Open unicode filename with C++
Hello
I have no idea how to open a file which its name is unicode letters ? usually :
Code:
basic_ifstream<wchar_t> src("source.txt");
Work well to read file with unicode content not filename, so that example doesn't work :
Code:
basic_ifstream<wchar_t> src(L"source.txt");
Also, I have seen some alternatives for using open function but it doesn't work as well.
Code:
basic_ifstream<wchar_t> src;
src.open(L"source.txt");
I use g++ compiler.
Regards
-
September 22nd, 2012, 08:36 PM
#2
Re: Open unicode filename with C++
Originally Posted by Emapat
Hello
I have no idea how to open a file which its name is unicode letters ?
You can use OS system calls or something like the boost file system library. The standard library has no say on file naming conventions or character set used for file names.
Regards,
Paul McKenzie
-
September 24th, 2012, 02:29 PM
#3
Re: Open unicode filename with C++
You could simply convert the name to ansi since (correct me if I'm wrong) unicode filenames are illegal in *nix.
Also, the L"blah blah" is not a unicode string, it is a wide string. Unicode starts with u and is only available in C++11.
-
September 24th, 2012, 03:54 PM
#4
Re: Open unicode filename with C++
>> (correct me if I'm wrong) unicode filenames are illegal in *nix.
In Linux (and other *nix are probably similar), most file systems deal with filenames as a stream of bytes and don't care about the encoding. So the encoding ultimately comes from the app creating the file. If your locale is UTF8, then it is possible to have UTF8 filenames. (If you mount an NTFS/FAT partition, there are mount options on how to handle filename encoding.)
>> Also, the L"blah blah" is not a unicode string ...
A more accurate statement would be:
"The encoding used for wide strings is implementation defined. On Windows, the encoding is UTF16LE. On *nix, the encoding is typically UTF32 in native byte order."
If using gcc or MSVC, wide strings are Unicode strings (of some encoding). But only a C++11 compiler can give you a guaranteed Unicode encoding of a string literal using u8/u/U.
In depth description of how string literals are encoded in MSVC and gcc can be found here: http://cboard.cprogramming.com/cplus...ml#post1086757
gg
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|