#include <fstream.h>
#include <stdlib.h>
const int MAXLENGTH = 21; // maximum file name length
char file1[MAXLENGTH];
int main()
{
ifstream in_file;
cout << "Please enter the name of the file you wish to open: ";
cin >> file1;
in_file.open(file1); // open the file
if (in_file.fail()) // check for successful open
{
cout << "\nThe file named " << file1 << " was not successfully opened"
<< "\n Please check that the file currently exists." << endl;
exit(1);
}
cout << "\nThe file has been successfully opened for reading.\n";
return 0;
}
--
※ 發信站: 批踢踢實業坊(ptt.twbbs.org)
◆ From: ntumcc66.mba.ntu.edu.tw