ifstream as global variable

I'm having trouble making this global and I can't figure out what Im' doing wrong. It was actually just a test SSCCI and still comming up with errors.
Error: as.h:line 12: ifstream does not name a type.
error:as.cpp: ifs has not been declared....has not been declared... has not been declared...etc

Is it not possible to have classes as global variables? or is there just a small typo somewhere?
AS.H
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#ifndef AS_H
#define AS_H

#include <fstream>

class as
{
   public:
      void openF();
      void closeF();
   private:
      ifstream ifs;

};

#endif 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "as.h"

#include <iostream>
#include <string>
using namespace std;

void as::openF()
{
   ifs.open("t.txt");
   string line;

   while (! ifs.eof())
   {
      getline(ifs, line);
      cout << line << endl;
   }
   cout << endl << endl << "EOF" << endl << endl;
}

void as::closeF()
{
   string line;

   if (ifs.good())
      cout << "is good" << endl;
   else
      cout << "is bad" << endl << endl << endl;

   while (!ifs.eof())
   {
      getline(ifs, line);
      cout << line << endl;
   }

   cout << endl << endl << "CLOSING NOW" << endl;
   ifs.close();

   if (ifs.good())
      cout << "IS GOOD" << endl;
   else
      cout << "IS BAD" << endl;
}
Last edited on
std::ifstream
it's going to be one of those days :(
thanks.

edit: now I've got a weird cygwin error:

1
2
usr/lib/gcc/i686-pc-cygwin/4.5.0/../../../libcygwin.a(libcmain.o):(.text+0xa9) undefinded reference to '_WinMain@16'
collect2: ld returned 1 exit status


yep...
Last edited on
Topic archived. No new replies allowed.