C++ issue. Need help.

I have been trying to make this program run. Its almost impossible for me to find out what the syntax error is.
Please help.

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
#include <fstream>
#include <conio.h>
#include <iostream>

int main()
{
	int x,y;
	ifstream f1("unu.in");
	ifstream f2("doi.in");
	ofstream f3("trei.out");
	f1 >> x;
	f2 >> y;
	while (!f1.eof()&&!f2.eof())
	{
		if (x < y)
		{
			f3 << x << " ";
			f1 >> x;
		}
		else
		{
			f3 << y << " ";
			f2 >> y;
		}
	}
	while (!f1.eof())
	{
		f3 << x << " ";
		f2 >> y;
	}
	
	f1.close();
	f2.close();
	f3.close();

	return 0;
}


1
2
3
4
5
6
7
8
9
10
11
12
13
Compiling source file(s)...
Prog4.cpp
Prog4.cpp: In function `int main()':
Prog4.cpp:8: error: `ifstream' undeclared (first use this function)
Prog4.cpp:8: error: (Each undeclared identifier is reported only once for each
function it appears in.)
Prog4.cpp:8: error: syntax error before `(' token
Prog4.cpp:10: error: `ofstream' undeclared (first use this function)
Prog4.cpp:11: error: `f1' undeclared (first use this function)
Prog4.cpp:12: error: `f2' undeclared (first use this function)
Prog4.cpp:17: error: `f3' undeclared (first use this function)

Prog4.exe - 7 error(s), 0 warning(s)
Last edited on
hi Guy, you need to use the namespace std, e.g. std::ifstream, or you can just "using namespace std;" before main function
jason yang wrote:
hi Guy, you need to use the namespace std, e.g. std::ifstream, or you can just "using namespace std;" before main function


Perfect.
Topic archived. No new replies allowed.