problem with opening a file

Hi so I am trying to open this file in my program, but I keep getting a few errors along with this function.. wondering what is wrong with it?

these are the errors:
error C2228: left of '.open' must have class/struct/union
error C2065: 'infile' : undeclared identifier
error C2228: left of '.eof' must have class/struct/union

Thank you in advance for taking a look at it!


1
2
3
4
5
6
7
8
9
10
11
12
13
void ReadData(string item[], int qty[], string location[], int price[], int NumProducts)
{
    infile.open("products.txt");

    while(!infile.eof())
    {
        getline(infile, item[NumProducts]); 
        getline(infile, qty[NumProducts]); 
        getline(infile, location[NumProducts]); 
        getline(infile, price[NumProducts]);  
    }
    infile.close();
}
You never declared infile. You either have to make it global, or to pass it as one of ReadData's arguments.
And compiler told you the same thing :)
that fixed those errors! but now there is these...

error C2039: 'open' is not a member of 'System::Int32'
error C2039: 'eof' is not a member of 'System::Int32'
infile has to be of type ifstream. You get that type from fstream.
Is this your code?
Topic archived. No new replies allowed.