[SOLVED]file input/output

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
Donutslayer7
Chaos Rift Newbie
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

Post 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. :)
Last edited by Donutslayer7 on Fri Mar 05, 2010 11:49 pm, edited 1 time in total.
XianForce
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 767
Joined: Wed Oct 29, 2008 8:36 pm

Re: file input/output

Post 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...
User avatar
Donutslayer7
Chaos Rift Newbie
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

Post by Donutslayer7 »

yeah, that's the strange thing, when I don't include my graphics lib, Fstream includes fine
User avatar
GroundUpEngine
Chaos Rift Devotee
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

Post 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?
User avatar
Donutslayer7
Chaos Rift Newbie
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

Post 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 :|
XianForce
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 767
Joined: Wed Oct 29, 2008 8:36 pm

Re: file input/output

Post 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'.
User avatar
Donutslayer7
Chaos Rift Newbie
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

Post 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. :)
XianForce
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 767
Joined: Wed Oct 29, 2008 8:36 pm

Re: file input/output

Post 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
K-Bal
ES Beta Backer
ES Beta Backer
Posts: 701
Joined: Sun Mar 15, 2009 3:21 pm
Location: Germany, Aachen
Contact:

Re: [SOLVED]file input/output

Post by K-Bal »

Remember to not use using namespace in header files. :)
Post Reply