Having an issue with <fstream>

This is the code. The compiler (Visual C++ 2010 Express) does not recognize the ifstream and ofstream even though the <fstream> header file is included. I have been writing many other codes using this type of input/output but never had this issue. Can anyone explain me why I am getting this ? Thanks in advance.

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <fstream>
#include <cmath>

long n, m;

int suma(int j, int k);
int fact(long p);

int main(int argc, char* argv[])
{
	long p;
	int i;

	ifstream inFILE("fact.in");
	ofstream outFILE("fact.out");

	inFILE >> p;
	outFILE << fact(p);

	return 0;
}

int suma(int j, int k)
{
	long s = 0;

	for (int i = 1; i <= k; i++)
	{
		s = s + floor(j / pow(5,(double)i));
	}

	return s;
}

int fact(long p)
{
	int i;
	long a, b, j;

	if (p == 0)
		return 1;
	else
	{
		m = 1;

		for(i = 1; m <= p;i++)
			m = m + pow(5,(double)i);

		if(p == m-1)
			return -1;
		else 
			m = m - pow(5,(double)--i);

		a = ceil(p * pow(5,(double)i) / m);
		b = floor((p + i) * pow(5,(double)i) / m);

		for(j = a; j < b; j++)
		{
			if (suma(j,i) == p)
				return j;
		}

		return -1;
	
	}

}


Edit: -- This is what the compiler returns:

1>d:\r++\c++\infoarena\factorial\factorial.cpp(14): error C2065: 'ifstream' : undeclared identifier
1>d:\r++\c++\infoarena\factorial\factorial.cpp(14): error C2146: syntax error : missing ';' before identifier 'inFILE'
1>d:\r++\c++\infoarena\factorial\factorial.cpp(14): error C3861: 'inFILE': identifier not found
1>d:\r++\c++\infoarena\factorial\factorial.cpp(15): error C2065: 'ofstream' : undeclared identifier
1>d:\r++\c++\infoarena\factorial\factorial.cpp(15): error C2146: syntax error : missing ';' before identifier 'outFILE'
1>d:\r++\c++\infoarena\factorial\factorial.cpp(15): error C3861: 'outFILE': identifier not found
1>d:\r++\c++\infoarena\factorial\factorial.cpp(17): error C2065: 'inFILE' : undeclared identifier
1>d:\r++\c++\infoarena\factorial\factorial.cpp(18): error C2065: 'outFILE' : undeclared identifier
Last edited on
You have to use the namespace std
Oh, right... I didn't realize I haven't had it added. Thanks a lot :)
Yeah welcome...
Another way is to write std:: in front of all the names from the standard library.
Topic archived. No new replies allowed.