Would anyone be able to help me with the following problem. I am trying to create a generic function, which accepts a stream name and the file name to open. The function output an error if it can't open the file. I've written some sample code to try and illustrate what I mean. Any ideas would be v.greatful thanks.
#include <iostream.h>
#include <fstream.h>
const int MAX_BUFFER=256;
void OpenFile(ifstream InFile, char FileName[MAX_BUFFER]);
int main()
{
char FileName[MAX_BUFFER]="Test.txt";
ifstream InFile;
OpenFile(InFile,FileName);
getchar();
return 0;
}
void OpenFile(ifstream InFile, char FileName[MAX_BUFFER])
{
InFile.open(FileName);
if(Infile.fail())
cout << "\nCould not open file.";
}