Page 1 of 1

[SOLVED]file input/output

Posted: Fri Mar 05, 2010 5:18 pm
by Donutslayer7
Hey, I've been using a graphics API called Allegro(which I'm sure we've all heard of). I hear it's pretty old, but now I want to use some file i/o(for map loading, save files, etc) and I'm not sure if I can run some useful libraries like Fstream alongside Allegro(I'll try to include fstream, but it says there is no such thing as fstream). I'm considering moving into SDL though(dunno, hear it used much more), so I'm wondering about how some of you are managing to do your file i/o with libraries like these. Maybe you know some good ways for this? Thanks. :)

Re: file input/output

Posted: Fri Mar 05, 2010 5:20 pm
by XianForce
Donutslayer7 wrote:Hey, I've been using a graphics API called Allegro(which I'm sure we've all heard of). I hear it's pretty old, but now I want to use some file i/o(for map loading, save files, etc) and I'm not sure if I can run some useful libraries like Fstream alongside Allegro(I'll try to include fstream, but it says there is no such thing as fstream). I'm considering moving into SDL though(dunno, hear it used much more), so I'm wondering about how some of you are managing to do your file i/o with libraries like these. Maybe you know some good ways for this? Thanks. :)
0.o... Well fstream is part of the C++ standard library... So if, when you attempt to compile, it says it doesn't exist, there was probably a mistake in installing whichever IDE you use...

Re: file input/output

Posted: Fri Mar 05, 2010 5:26 pm
by Donutslayer7
yeah, that's the strange thing, when I don't include my graphics lib, Fstream includes fine

Re: file input/output

Posted: Fri Mar 05, 2010 5:36 pm
by GroundUpEngine
Donutslayer7 wrote:yeah, that's the strange thing, when I don't include my graphics lib, Fstream includes fine
Dude that's wierd! Could post some of your code?

Re: file input/output

Posted: Fri Mar 05, 2010 10:57 pm
by Donutslayer7
alright, here's a snippet of some of my old code:

Code: Select all

#include <allegro.h>
#include <fstream>
BITMAP *buffer;
BITMAP *bax;
BITMAP *tile;
BITMAP *start;
BITMAP *character;
ofstream data;//ofstream doesn't work
int mode(0);
int tilesize = 30;
int y = 14 *tilesize;
int x = 1 * tilesize;
int xtile, ytile, xtile2, ytile2;
int dx;
int map[16][22] = {
    {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
    {1,3,3,1,1,1,3,3,1,1,1,1,1,1,3,3,3,1,3,3,1,1},
    {1,0,0,3,1,3,0,0,3,1,3,3,1,3,0,0,0,3,0,0,1,1},
    {1,0,0,0,3,0,0,0,0,3,0,0,3,0,0,0,0,0,0,0,1,1},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
    {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
    {1,0,0,0,0,0,0,2,0,0,2,0,0,0,0,0,0,0,0,0,1,1},
    {1,0,0,0,0,0,2,1,2,2,1,2,0,0,0,2,0,0,0,0,0,0},
    {1,0,0,0,0,2,1,1,1,1,1,1,2,0,2,1,2,0,0,2,1,1},
    {1,0,2,2,2,1,1,1,1,1,1,1,1,2,1,1,1,2,2,1,1,1},
    {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
};
Turns out it I had to put "fstream", not "fstream.h", but the file declarations still won't work :|

Re: file input/output

Posted: Fri Mar 05, 2010 11:01 pm
by XianForce
Okay, I see you declaring an 'ostream' object, but no declaration of 'using namespace std'. If you don't put that line in, then you need to specify that ostream is part of the std namespace, so: 'std::ostream'.

Re: file input/output

Posted: Fri Mar 05, 2010 11:49 pm
by Donutslayer7
Ah, that make perfect sense, using namespace std exactly as if you were using it for iostream. Thanks, the files are loading now. :)

Re: file input/output

Posted: Sat Mar 06, 2010 12:11 am
by XianForce
Donutslayer7 wrote:Ah, that make perfect sense, using namespace std exactly as if you were using it for iostream. Thanks, the files are loading now. :)
No problem, glad I could help =D

Re: [SOLVED]file input/output

Posted: Sat Mar 06, 2010 4:35 am
by K-Bal
Remember to not use using namespace in header files. :)