Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Using std::fstream and PhysicsFS.

Credits go to Thomas Fjellstrom for helping out!
This thread is locked; no one can reply to it. rss feed Print
Using std::fstream and PhysicsFS.
Eric Johnson
Member #14,841
January 2013
avatar

Hi there. I recently incorporated PhysFS in a project of mine to read the contents of archive (.zip) files. All was well until I attempted to load a text file using std::fstream. No matter what I tried, the text file could not be found.

My thinking is that al_set_physfs_file_interface() works only with Allegro-specific calls (such as al_load_bitmap() and ALLEGRO_FILE), but does not affect things outside of Allegro (such as std::fstream). Is my thinking correct?

I have attached an example that attempts to load a text file from an archive. It first uses std::fstream, and then ALLEGRO_FILE. ALLEGRO_FILE is successful, but std::fstream is not. On Linux, I am using g++ -Wall -o test main.cpp -lphysfs $(pkg-config --libs allegro-5 allegro_physfs-5) to compile from a command line.

TL;DR: Can al_set_physfs_file_interface() be used with std::fstream?

Thank you for your time. :)

--
EricII on #allegro.
My Games
Momo (my JS game-making library)

Thomas Fjellstrom
Member #476
June 2000
avatar

It could be used if you wrote specialized fstream subclasses that work on ALLEGRO_FILE's or directly with PhysFS, but as is, no.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Eric Johnson
Member #14,841
January 2013
avatar

Thank you for your swift reply, Thomas.

Okay, no worries then. ALLEGRO_FILE makes things a bit easier anyhow. ;)

--
EricII on #allegro.
My Games
Momo (my JS game-making library)

Go to: