Need help with- read a file using a class

Hello everyone! I'm new to programming and my question is, how do you read a file using a class?

the contents in my file:

123 Larry Herp 001
456 Berry Perp 002
789 Ferry Berp 003

I could read this file in my main, but i want to read it in class and call the class in main.

void main()
{
int ticketnumber, seatnumber;
string firstName;
string lastName;

ifstream file;
file.open("data.txt");

if (file.fail())
{
cout<<"Issue(101)"<<endl;
exit(1);
}

while(!file.eof())
{
file >> ticketnumber >> firstName>> lastName>> seatnumber;
cout<<ticketnumber<< " "<<firstName<< " "<<lastName<<" "<<seatnumber<<endl;
}
file.close();
system("pause");
}

I think I could set up the class like this:

class people
{
public:
people();
people(int ticketnumber, string firstName, string lastName, int seatnumber);
~people();
void displayFile(); // use this constructor to display the contents in file? but i don't know how.
}

Could anyone give me some ideas? thank you :)



Last edited on
Topic archived. No new replies allowed.