Dear David and all,

On 21.03.2017 04:14, David Grayson wrote:
> Like I said, you should run "_wfopen(L"E:/Some/File.txt", L"rb");" so you 
> narrow this down to either a problem with your C++ code or a problem with 
> _wfopen.

I could narrow down the problem, and actually it seems to be mostly
a complete ignorance on my side about how unicode, utf8, utf16, wchar
etc work. I was under the (naiive?) assumption that I could convert a
std::string to std::wstring with the codecvt converter from C++11
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> and
would just get the same string in a different representation, at least
for some basic ASCII. This seems far from reality! :-( :-( :-(

In fact, it has nothing to do with Windows. Also on Linux, the following
does not do what I expect:

std::string vCharStr = "hello world";
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> 
utf8_to_utf16_converter;
std::wstring vWCharStrFromCharStr = 
utf8_to_utf16_converter.from_bytes(vCharStr);
std::wcout << "vWCharStrFromCharStr = '" << vWCharStrFromCharStr << "'" << 
std::endl;
// shows only unprintable characters

I tried many combinations of converters, but no luck so far. And
I can not find a reasonable description of this simple task. There
are hundreds of websites that discuss asian characters, but not one
that just explains how to convert basic ASCII between character
types. I guess I have to go to a generic C++ mailing list with this
problem, or is anybody by chance able to help?

Thanks and all the best,

    Mario



> --David
> 
> On Mon, Mar 20, 2017 at 4:32 PM, Mario Emmenlauer <ma...@emmenlauer.de 
> <mailto:ma...@emmenlauer.de>> wrote:
> 
> 
>     Sorry, here is the corrected example:
> 
>       std::string aFileName = "E:/Some/File.txt";
>       std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> 
> converter;
>       std::wstring vFileName = converter.from_bytes(aFileName);
>       FILE *in_stream = _wfopen(vFileName.c_str(), L"rb");
>       // in_stream is NULL here
> 
>     The same code with fopen() on the original std::string works:
>       std::string aFileName = "E:/Some/File.txt";
>       FILE *in_stream = fopen(aFileName.c_str(), "rb");
>       // in_stream is a correctly opened file here
> 
>         All the best,
> 
>             Mario Emmenlauer
> 
> 
>     On 21.03.2017 00 <tel:21.03.2017%2000>:27, David Grayson wrote:
>     > You must be doing something wrong because aFileName is set but not used 
> in the
>     > first example.
>     >
>     > You should try doing something like _wfopen(L"E:/Some/File.txt", 
> L"rb"); so that
>     > you can verify that _wfopen works without strange C++ stuff.
>     >
>     > --David
>     >
>     > On Mon, Mar 20, 2017 at 4:21 PM, Mario Emmenlauer <ma...@emmenlauer.de 
> <mailto:ma...@emmenlauer.de>
>     > <mailto:ma...@emmenlauer.de <mailto:ma...@emmenlauer.de>>> wrote:
>     >
>     >
>     >     I have a problem with code that is using _wfopen() on Windows. 
> Should it
>     >     work with MSYS2? I have the following code that fails:
>     >
>     [...]
>     >
>     >     Is that to be expected, or am I doing something wrong?
>     >
>     >     All the best,
>     >
>     >         Mario Emmenlauer
> 
> 
> 



Viele Gruesse,

    Mario Emmenlauer


--
BioDataAnalysis GmbH, Mario Emmenlauer      Tel. Buero: +49-89-74677203
Balanstr. 43                   mailto: memmenlauer * biodataanalysis.de
D-81669 München                          http://www.biodataanalysis.de/

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Msys2-users mailing list
Msys2-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/msys2-users

Reply via email to