I am trying to gain a better understanding of reading a file and getline. I need to be able to read and output a file one line at a time. The file contains 5 short lines each ending with a period. I need to read a different line with each pass. I wrote this little program to try to help me understand this. Rather than loop through and read each line one at a time, the program reads the first line of the text file and ends. Any help with understanding this would be appreciated.
Thanks.
Kyle
The answerfile.txt file looks like:Code:#include <fstream>
#include <iostream>
#include <cstdlib>
using namespace std;
using std::ifstream;
newLine(ifstream& fin);
int main()
{
char question=0;
ifstream fin;
fin.open("A:\\answerfile.txt");
for(int i=0;i<5;i++);
{
newLine(fin);
}
return 0;
}
newLine(ifstream& fin)
{
char answerfile[50];
fin.getline(answerfile,50, '\n');
cout<<answerfile<<endl;
return 0;
}
Test answer one.
Test answer two.
Test answer three.
Test answer four.
Test answer five.