Code:
readinfile(char * file) //Opens file and read information
{
file = "file.txt";
Why send a parameter that you change and never use?
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):
Code:
class ReadClass
{
public:
bool ReadFile(const char* FileName);
};
ReadClass::ReadFile(const char* FileName)
{
ifstream File;
File.open(FileName, ios::in);
if(File.fail()) return false;
//*** Do reading operatons here ***
File.close();
return true;
}
int main()
{
ReadClass MyClass;
char FileNameBuffer[64];
cin >> FileNameBuffer;
MyClass.ReadFile(FileNameBuffer);
return 0;
}