[OT]-Visual Studio/Code::Blocks Troubles

[OT]-Visual Studio/Code::Blocks Troubles…

Hi,

We are trying to build an MS Visual Studio 13 project using Windows® 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::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 <AT> GMail <DOT> com
16BitSoft Inc.
Video Game Design Studio
www.16BitSoft.com

Hi,

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

Any other ideas?
Thanks!------------------------
JeZxLee
JessePalser <AT> GMail <DOT> com
16BitSoft Inc.
Video Game Design Studio
www.16BitSoft.com

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!------------------------
JeZxLee
JessePalser <AT> GMail <DOT> com
16BitSoft Inc.
Video Game Design Studio
www.16BitSoft.com

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 filebuf(_wfopen(wstr, L"rb"), ios::in);
basic_istream 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>
#endifOn 02/05/15 03:38, JeZ-l-Lee wrote:

[OT]-Visual Studio/Code::Blocks Troubles…

Hi,

We are trying to build an MS Visual Studio 13 project using Windows® 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::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 <AT> GMail <DOT> com
16BitSoft Inc.
Video Game Design Studio
www.16BitSoft.com


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Could also try std::fstream::in too, just on case

Could also try std::fstream::in

Have you made sure your project settings are setup for wide characters (and not standard ASCII?)

I presume you have #include ?

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 filebuf(_wfopen(wstr, L"rb"), ios::in);
basic_istream 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’ has no member named ‘is_open’|

What we do now?
Thanks!------------------------
JeZxLee
JessePalser <AT> GMail <DOT> com
16BitSoft Inc.
Video Game Design Studio
www.16BitSoft.com

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’ 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*>(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.

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!------------------------
JeZxLee
JessePalser <AT> GMail <DOT> com
16BitSoft Inc.
Video Game Design Studio
www.16BitSoft.com

There’s an example on this page: https://wiki.libsdl.org/SDL_RWwrite