[SOLVED]file input/output
Moderator: Coders of Rage
- Donutslayer7
- Chaos Rift Newbie
- Posts: 16
- Joined: Tue Aug 18, 2009 5:16 pm
- Current Project: Map-Editor
- Favorite Gaming Platforms: N64, SNES, anything Nintendo
- Programming Language of Choice: C++
- Location: U.S.
[SOLVED]file input/output
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.
Last edited by Donutslayer7 on Fri Mar 05, 2010 11:49 pm, edited 1 time in total.
Re: file input/output
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...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.
- Donutslayer7
- Chaos Rift Newbie
- Posts: 16
- Joined: Tue Aug 18, 2009 5:16 pm
- Current Project: Map-Editor
- Favorite Gaming Platforms: N64, SNES, anything Nintendo
- Programming Language of Choice: C++
- Location: U.S.
Re: file input/output
yeah, that's the strange thing, when I don't include my graphics lib, Fstream includes fine
- GroundUpEngine
- Chaos Rift Devotee
- Posts: 835
- Joined: Sun Nov 08, 2009 2:01 pm
- Current Project: mixture
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C++
- Location: UK
Re: file input/output
Dude that's wierd! Could post some of your code?Donutslayer7 wrote:yeah, that's the strange thing, when I don't include my graphics lib, Fstream includes fine
- Donutslayer7
- Chaos Rift Newbie
- Posts: 16
- Joined: Tue Aug 18, 2009 5:16 pm
- Current Project: Map-Editor
- Favorite Gaming Platforms: N64, SNES, anything Nintendo
- Programming Language of Choice: C++
- Location: U.S.
Re: file input/output
alright, here's a snippet of some of my old code:
Turns out it I had to put "fstream", not "fstream.h", but the file declarations still won't work
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},
};
Re: file input/output
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'.
- Donutslayer7
- Chaos Rift Newbie
- Posts: 16
- Joined: Tue Aug 18, 2009 5:16 pm
- Current Project: Map-Editor
- Favorite Gaming Platforms: N64, SNES, anything Nintendo
- Programming Language of Choice: C++
- Location: U.S.
Re: file input/output
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
No problem, glad I could help =DDonutslayer7 wrote:Ah, that make perfect sense, using namespace std exactly as if you were using it for iostream. Thanks, the files are loading now.
Re: [SOLVED]file input/output
Remember to not use using namespace in header files.