C2146 Syntax error

I have the following lines in my program:

1
2
3
4
5
#include <fstream>
...
extern void LANG1_main();
extern ifstream ifile;
extern ofstream ofile;


After building, Visual Studio says about the last-but-one line: "C2146 Syntax error: missing ‘;’ before identifier ‘ifile’".

There is a similar message about the last line.

I have looked up C2146 but cannot find any answer.

The definitions of ifile and ofile are:

1
2
ifstream ifile("in_filename"); 
ofstream ofile("out_filename"); 


Please can anyone tell me how these errors may be corrected.
ifstream and ofstream are part of std namespace. Hence, you need std:: in front of the types:
1
2
3
4
5
#include <fstream>
...
extern void LANG1_main();
extern std::ifstream ifile;
extern std::ofstream ofile;
or you may write
using namespace std;

By the way: it is certainly not a good idea to use stream as global variables. Actually it is not a good idea to use global variables when there are alternatives.
Thanks for this. By a bit more digging, I'd arrived at much the same conclusion.
Topic archived. No new replies allowed.