Can't get extern to work with istream or ostream in Linux

I just don't get it!

I completed my program for school, was ready to turn it in before midnight. Then I tried compiling it on Linux.

I can't use extern for ifstream and ofstream like I did in Visual Studio. There are other files involved but it essentially comes down to this.


1
2
3
4
// HEADER FILE

extern ifstream fin;
extern ofstream fout;


1
2
3
4
// Main File

ifstream fin = ifstream();
ofstream fout = ofstream();

Basically, this worked in Visual Studio but did not in Linux.



I feel like this is either very arcane or blatantly obvious. Any thoughts most absolutely appreciated.
Last edited on
"did not work" is not an error message.
1
2
3
> // HEADER FILE
> extern ifstream fin;
> extern ofstream fout;


Avoid dumping namespace using directives / declarations in a header file.

1
2
3
4
5
6
7
8
9
// HEADER FILE

// using namespace std ;

// extern ifstream fin;
extern std::ifstream fin;

// extern ofstream fout;
extern std::ofstream fout;




1
2
> ifstream fin = ifstream();
> ofstream fout = ofstream();

> Basically, this worked in Visual Studio but did not in Linux

This would work everywhere:

1
2
3
4
5
// ifstream fin = ifstream();
std::ifstream fin ;

// ofstream fout = ofstream();
std::ofstream fout ;


Note: file streams are MoveConstructible in conforming implementations. However, many (most?) linux distributions ship with versions of the GNU implementation before GCC 5.2, where the standard C++ library implementation is broken in more places than one would care to enumerate.
closed account (48T7M4Gy)
where the standard C++ library implementation is broken in more places than one would care to enumerate.


Então vá e corrigi-lo!
Topic archived. No new replies allowed.