#include <fstream.h>
#include <stdlib.h>
#include <iomanip.h>
const int MAXLENGTH = 21; // maximum file name length
const int MAXCHARS = 80; // maximum line length
char file1[MAXLENGTH] = "prices.dat";
int main()
{
int ch;
char line[MAXCHARS];
ifstream in_file;
in_file.open(file1);
if (in_file.fail()) // check for successful open
{
cout << "\nThe file was not successfully opened"
<< "\n Please check that the file currently exists."
<< endl;
exit(1);
}
cout << endl; // start on a new line
// now read the file
while( (ch = in_file.peek()) != EOF )
{
in_file.getline(line,MAXCHARS,'\n');
cout << line << endl;
}
in_file.close();
return 0;
}
--
※ 發信站: 批踢踢實業坊(ptt.twbbs.org)
◆ From: ntumcc66.mba.ntu.edu.tw