I'm trying to read information from a text file and populate an array of structs using a pointer. I keep getting an error and I'm not sure how to fix it. Any help, comments, or tips are greatly appreciated! Thanks in advance for your time and help!
error: request for member 'budget_num'in 'ptr', which is of non-class type 'budget*'
struct budget
{
int budget_num;
string name;
float budget_value;
};
//Declare file streams
ifstream inFile;
ofstream outFile;
int main()
{
//Declare variables
budget company[15];
budget *ptr;
//string MyString = "";
ptr = &company[0];
//Open inFile
inFile.open("ledger.dat");
while(!inFile)
{
cout << "Error opening the inFile." << endl;
return 1;
}
while(!inFile.eof())
{
for(ptr = &company[0]; ptr < &company[15]; ptr++)
{
cin(inFile, ptr.budget_num);
cin(inFile, ptr.name);
cin(inFile, ptr.budget_value);
//getline(inFile, MyString); //Used to test to see if the information was coming in
}
}
//Close the files
inFile.close();
//Exit program
return EXIT_SUCCESS;
}