Ifstream problem with displaying lines.
Jul 12, 2012 at 3:30am UTC
I am trying to display the contents of each file at a time with this function, but the problem is it is displaying
numberOfLines correctly but they are all blank, so something is happening that it cannot read the lines, I dont know :). Can somebody please help me..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
void WordSearch::openInFile(ifstream& fin, int index)
{
char a[120];
string *lines;
int numOfLines;
fin.open(string(directory+"\\" +files[index]).c_str());
if (fin.fail( ))
{
cerr << "Input file opening failed.\n" ;
//cout << directory << "\\" << files[index] << endl; ERROR CHECKING
//exit(1);
}
else
{
cout << files[index] << " Opened." << endl;
numOfLines = getNumofLines(fin);
lines = new string[numOfLines];
for (int i = 0;i<numOfLines;i++)
{
fin.getline(a,120);
lines[i] = a;
cout << lines[i] << endl;
}
}
//cout << endl << index << endl; ERROR CHECKING
}
I am using this to call the previous function.
1 2 3 4 5 6 7 8 9 10 11 12
int WordSearch::stringSearch()
{
for (unsigned int i = 2; i < files.size();i++)
{
ifstream fins;
openInFile(fins, i);
fins.close();
fins.clear();
}
}
Thank you in advanced, I know everybody here knows what to do, so I have faith in getting help :)
SOLVED
Last edited on Jul 12, 2012 at 3:53am UTC
Topic archived. No new replies allowed.