The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
[OT]-Visual Studio/Code::Blocks Troubles...
JeZ-l-Lee


Joined: 20 Sep 2009
Posts: 572
Location: Long Island, New York, United States, Earth
[OT]-Visual Studio/Code::Blocks Troubles...

Hi,

We are trying to build an MS Visual Studio 13 project using Windows(R) Code::Blocks,
but am having trouble with the following:
Code:
if __WINDOWS__
   wchar_t *wstr = (wchar_t *)SDL_iconv_utf8_ucs2(filename);
   fstream fileStream;
   fileStream.open(wstr, fstream::in); //<--ERROR(Below)
   SDL_free(wstr);
#else
   fstream fileStream;
   fileStream.open(filename, fstream::in);
#endif

and we get this error:
Code:
C:\Users\Jesse Palser\Desktop\2D-RPG\src\data.cpp|234|error: no matching function for call to 'std::basic_fstream<char>::open(wchar_t*&, const openmode&)'|

any idea on how to fix the above?
Thanks!

The purpose of the above code is so we can support non-English letter file paths...
MrTAToad


Joined: 13 Feb 2014
Posts: 205
Location: Chichester, England
I presume you have #include <fstream> ?
MrTAToad


Joined: 13 Feb 2014
Posts: 205
Location: Chichester, England
Could also try std::fstream::in too, just on case
MrTAToad


Joined: 13 Feb 2014
Posts: 205
Location: Chichester, England
Could also try std::fstream::in
JeZ-l-Lee


Joined: 20 Sep 2009
Posts: 572
Location: Long Island, New York, United States, Earth
Hi,

Thanks.
We already have "#include <fstream>".
We tried changing it to "std::fstream::in" but it still has error?

Any other ideas?
Thanks!
MrTAToad


Joined: 13 Feb 2014
Posts: 205
Location: Chichester, England
Have you made sure your project settings are setup for wide characters (and not standard ASCII?)
JeZ-l-Lee


Joined: 20 Sep 2009
Posts: 572
Location: Long Island, New York, United States, Earth
MrTAToad wrote:
Have you made sure your project settings are setup for wide characters (and not standard ASCII?)
Hi,

Ok, any idea how to setup Code::Blocks to support wide characters?
(Google was no help)

Thanks!
[OT]-Visual Studio/Code::Blocks Troubles...
Alex Baines
Guest

The problem is that the fstream.open method which takes a wchar_t* is a
non-standard addition to MSVC's standard library.

You could try setting Code::Blocks to use the Microsoft C++ SDK if it
can, that way the current code should work.

If it's using GCC or a derivative like mingw, then you can possibly use
the stdio_filebuf extension instead, like so:

#if __WINDOWS__
wchar_t *wstr = (wchar_t *)SDL_iconv_utf8_ucs2(filename);
#ifdef __GNUC__
__gnu_cxx::stdio_filebuf<char> filebuf(_wfopen(wstr, L"rb"), ios::in);
basic_istream<char> fileStream(&filebuf);
#else
fstream fileStream(wstr, fstream::in);
#endif
SDL_free(wstr);
#else
fstream fileStream(filename, fstream::in);
#endif

you might need to add the following earlier in the file:
#ifdef __GNUC__
#include <ext/stdio_filebuf.h>
#endif

On 02/05/15 03:38, JeZ-l-Lee wrote:
Quote:
[OT]-Visual Studio/Code::Blocks Troubles...

Hi,

We are trying to build an MS Visual Studio 13 project using Windows(R) Code::Blocks,
but am having trouble with the following:

Code:
if __WINDOWS__
wchar_t *wstr = (wchar_t *)SDL_iconv_utf8_ucs2(filename);
fstream fileStream;
fileStream.open(wstr, fstream::in); //<--ERROR(Below)
SDL_free(wstr);
#else
fstream fileStream;
fileStream.open(filename, fstream::in);
#endif


and we get this error:

Code:
C:\Users\Jesse Palser\Desktop\2D-RPG\src\data.cpp|234|error: no matching function for call to 'std::basic_fstream<char>::open(wchar_t*&, const openmode&)'|


any idea on how to fix the above?
Thanks!

The purpose of the above code is so we can support non-English letter file paths...

------------------------
JeZxLee
JessePalser &lt;AT&gt; GMail &lt;DOT&gt; com
16BitSoft Inc.
Video Game Design Studio
www.16BitSoft.com







_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
JeZ-l-Lee


Joined: 20 Sep 2009
Posts: 572
Location: Long Island, New York, United States, Earth
Hi,

Thanks for the code.
Code:
#ifdef __GNUC__
#include <ext/stdio_filebuf.h>
#endif

Code:
#if __WINDOWS__
    wchar_t *wstr = (wchar_t *)SDL_iconv_utf8_ucs2(filename);
    #ifdef __GNUC__
        __gnu_cxx::stdio_filebuf<char> filebuf(_wfopen(wstr, L"rb"), ios::in);
        basic_istream<char> fileStream(&filebuf);
    #else
        fstream fileStream(wstr, fstream::in);
    #endif
    SDL_free(wstr);
#else
    fstream fileStream(filename, fstream::in);
#endif

if (fileStream.is_open())//<-ERROR{

We added the new code but have error:
Code:
C:\Users\Jesse Palser\Desktop\LF-WinLinux\src\data.cpp|248|error: 'class std::basic_istream<char>' has no member named 'is_open'|

What we do now?
Thanks!
[OT]-Visual Studio/Code::Blocks Troubles...
Alex Baines
Guest

Quote:
We added the new code but have error:

Code:
C:\Users\Jesse Palser\Desktop\LF-WinLinux\src\data.cpp|248|error: 'class std::basic_istream<char>' has no member named 'is_open'|


What we do now?
Thanks!

It's a bit of a hack, but you can use
reinterpret_cast<basic_filebuf<char>*>(fileStream.rdbuf())->is_open()
instead of
fileStream.is_open()

Also, now that I think about it you might need to add:
#if __WINDOWS__ && __GNUC__
fclose(filebuf.file());
#endif
when you're done reading, to make sure the file is closed.

And in the writing code change basic_istream to basic_ofstream and L"rb"
to L"wb".

Kinda messy, unfortunately. You might be better off ditching the
fstreams and using something like SDL_RWops that handle the unicode
conversion transparently if you want cleaner code.
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Re: [OT]-Visual Studio/Code::Blocks Troubles...
JeZ-l-Lee


Joined: 20 Sep 2009
Posts: 572
Location: Long Island, New York, United States, Earth
Alex Baines wrote:
... Kinda messy, unfortunately. You might be better off ditching the
fstreams and using something like SDL_RWops that handle the unicode
conversion transparently if you want cleaner code.
Hi,

Forgive, but I never used SDL_RWops before...
Could someone give an example which would work?

Thanks!
[OT]-Visual Studio/Code::Blocks Troubles...
Alex Baines
Guest

There's an example on this page: https://wiki.libsdl.org/SDL_RWwrite
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org