Sign in to follow this  
ugoel123

iostream file open with Unicode string

Recommended Posts

ugoel123    122
Hi all, I want to use ifstream and fstream functions with unicode charaters. Can any one suggest me the way. I already converted strings into UTF8 and tried to set locale with the following: _wsetlocale(LC_ALL , L"Chinese.1200"); int cpset = _setmbcp(65001/*code page no for UTF8*/) but it did not help. Can any one suggest something from here. --Umesh

Share this post


Link to post
Share on other sites
ugoel123    122
hi,
suggestion is good but I can't use wfstream since fstream is in the DLL, of which we doesn't have source code. I just need to pass one argument of file name to the DLL which they will use for fstream. So your suggestion may not work here.

Share this post


Link to post
Share on other sites
snk_kid    1312
That was me, again for unknown reasons i was logged out that took out all my formatting and messed up some of the words [flaming]. Please ignore the above post and read this one instead:

Quote:
Original post by ugoel123
... I want to use ifstream and fstream functions with unicode charaters ...

Quote:
Original post by ugoel123
... but I can't use wfstream since fstream is in the DLL ...


Well your pretty much stuck then, if didn't realize those types are type aliases of class templates instanciations. The C++ iostreams are class templates that are parameterized by character type, character traits and (depending on the stream) may also have an allocator type. std::ifstream and std::fstream are type aliases with the character type char and the character traits std::char_traits<char>.

All C++ iostreams have an associated locale object its type is called std::locale it is the heart of the iostreams localized/internationalized parsing/formatting layer, where a locale object contains many facet objects that each does a particular parsing/formatting task.

When an iostream is constructed and an instance of C++ locale not explicitly specified for an iostream one is provided by default which is a snapshot of the C++ global locale object (a copy of it). C++ locales are kind of related to C locales however changing the C global locale does not change/effect the C++ global locale object but the reserve is not true changing the C++ global locale may effect the C global locale.

You can change the locale instance associated with a stream at any time, you can associate/add different facet instances to a locale object at any time. This means you can change character conversion etc of a stream such that it writes to any kind of character encoding of an external representation (such as file), however because you have an instance of fstream/ifstream in a DLL it is impossible for you to make the iostream interface (the internal representation) work wide character type or any other character types in your program because its an instance of std::basic_(i)fstream<char, std::char_traits<char> >.

[Edited by - snk_kid on July 20, 2005 5:58:22 AM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this