-2
#include <iostream>
#include <fstream>
#include <cstdio>
#include <stdio.h>
using namespace std;
int v[101];

int main()
{
int max=0; int a,i;
ifstream f("bac.in");
ofstream g("bac.out");

while(!EOF(f))
{
    f >> a;
    while(a>10)
      if(a%10!=0 && (a/10)%10!=0)  v[a%100]++;
    a/=10;
}
for(i=10;i<=99;i++) if(v[i]>max) max=v[i];
for(i=10;i<=99;i++) if(v[i]==max) g<<i;

}

I get the error 14 | error: '-1' cannot be used as a function
If i use eof instead of EOF i get the error 'eof' was not included in this scope but i have already included cstudio or studio.h
What should i change?

Cioby Andrei
  • 67
  • 1
  • 7

1 Answers1

1

EOF is not a function, it's a constant. However, you shouldn't be using eof to find the end of file anyway (here is why).

Put reading itself into loop header, like this:

while(f >> a) {
    while(a>10)
      if(a%10!=0 && (a/10)%10!=0)  v[a%100]++;
    a/=10;
}

The reason this works is that f >> a, which returns istream, has a conversion operator* which allows the expression to be used as a condition. When the read is successful, the resultant condition evaluates to true; otherwise, it's false.

* The details of the conversion are different in C++98 and C++11/14, but the expression remains valid regardless of the C++ standard.

Community
  • 1
  • 1
Sergey Kalinichenko
  • 675,664
  • 71
  • 998
  • 1,399
  • @CiobyAndrei You are welcome! If the problem is solved, consider accepting the answer by clicking the grey check mark next to it. This would let others know that you are no longer actively looking for an improved solution, and earn you a new badge on Stack Overflow. – Sergey Kalinichenko Apr 30 '15 at 16:27