Click to See Complete Forum and Search --> : fstream/iostream headers


saai
12-09-2000, 06:50 PM
I am trying to write some file handling routines for my program, using C++ on slackware 7.0.

I have several function prototypes in my own header file that return an fstream object. My problem is, when I include fstream(.h) or iostream(.h) in the same header file, followed by 'using namespace std;', I get the following error:

In file included from /usr/include/g++-2/iostream.h:31,
from /usr/include/g++-2/fstream.h:30,
from filesystem.h:7, (my file)
from menu.h:12, (my file)
from main.cc:10: (my file)
/usr/include/g++-2/streambuf.h:210: arguments given to macro 'clear'
In file included from /usr/include/g++-2/fstream.h:30,
from filesystem.h:7, (my file)
from menu.h:12, (my file)
from main.cc:10, (my file)
/usr/include/g++-2/iostream.h:186: arguments given to macro 'clear'
/usr/include/g++-2/iostream.h:189: arguments given to macro 'clear'

The file be compiled is main.cc. Does anyone know why this is happening?

Thanks,

Saai

Strike
12-09-2000, 06:51 PM
How about posting the code in main.cc (specifically line 10, but all of it would be nice if it's not too long)?

saai
12-09-2000, 09:05 PM
Sorry, I should have posted the code in my first post. But anyway, here is part of main.cc, which contains only the main() function, which initalizes ncurses then calls a function declared in menu.h.

#include <stdlib.h>
#include "graphics.h"
#include "input.h"
#include "menu.h" // <<< line 10
#include "log.h"

menu.h contains menu systems and related code, like the main menu of my program. This is menu.h:

#include <stdlib.h>
#include <unistd.h>
#include "graphics.h"
#include "input.h"
#include "filesystem.h" // <<< line 12
#include "monsters.h"

And, in filesystem.h:

#include <fstream.h> // <<< line 7
using namespace std;
#include "log.h"

Every part I listed above is the beginning of each file, they don't start at line 1 because I have commenting above them. Currently no code in filesystem.h is being used by the rest of the program.

Saai

Glaurung
12-10-2000, 04:19 PM
int clear(void) from ncurses.h probably conflicts with void clear(iostate) from ios. I'm not sure though.

Try one of the following and see if it helps:
1) don't include the entire std namespace, use just what you need.
2) make a header, eg. ncurses++.h, containing the line

namespace ncurses { #include <ncurses.h> }

In your program, don't use namespace ncurses, but specify the functions explicitely, eg. ncurses::some_function

Hope this helps