how do u read in from file using a class...I want user to enter name of filetopoen

how do u read in from file using a class...I want user to enter name of filetopoen

This is a discussion on how do u read in from file using a class...I want user to enter name of filetopoen within the C++ Programming forums, part of the General Programming Boards category; class readinfile {
public:
readinfile(char * file) //Opens file and read information
{
file = "file.txt";
ifstream infile;
infile.open(file);
char ...

Try this basic layout. I think it's nicer layout if you put the cin in main instead of the constructor, and using a method instead of the constructor to open the file (so you can control when it's opened, not just when the object is created. If you do want it to open at startup, call it in the constructor):