Hello,
I am trying to read and display the contents of the following text file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
Harry Potter and the Deathly Hallows
J K Rowlin and Mary GrandPré
0545010225
20.99
Pride and Prejudice
Jane Austen
0307386864
7.95
Wuthering Heights
Emily Bronte
0553212583
4.95
# include <iostream>
# include <fstream>
usingnamespace std;
int main()
{
constint size = 50;
char Title[ size ];
char Author[ size ];
char ISBN[ size ];
char price[ size ];
char line[ size ];
ofstream outfile;
outfile.open("myfilename.txt",ios::app);
outfile.close();
ifstream infile;
infile.open("myfilename.txt");
while ( infile )
{
if (infile == false)
cout<<"Could not open the input file"<<endl;
// read another record
infile.getline( Title, size );
infile.getline( Author, size );
infile.getline( ISBN, size );
infile.getline( price, size );
infile.getline( line, size );
// display
cout << Title << endl
<< Author << endl
<< ISBN << endl
<< price << endl << endl;
}// end while
infile.close();
system ("pause");
}
1 2 3 4 5 6 7 8 9 10 11
Harry Potter and the Deathly Hallows
J K Rowlin and Mary GrandPré
0545010225
20.99
Pride and Prejudice
Jane Austen
0307386864
7.95
------------------------------------
Wuthering Heights
Emily Bronte
0553212583
4.95
------------------------------------