J
Joe
Hello -
I wrote a program that uses ifstream to open an ASCII file and
getline() to read in the lines. The problem is when I try to open the
same file again later in the code. I used close() to close the file
but the next open() fails. If I comment out the getline() then I can
open it a second time without a problem. Here are parts of the code:
ifstream InputFile;
char Line[MAXcharLine + 1]; // MAXcharLine = 512
InputFile.open("X.dat");
if (InputFile == NULL)
{
cerr << "Error at " << __LINE__ << ": Could not open file 'X.dat'"
<< endl;
return false;
}
while (InputFile.getline(Line, MAXcharLine))
{
// STUFF
}
InputFile.close();
....
InputFile.open("X.dat");
// This here fails!
if (InputFile == NULL)
{
cerr << "Error at " << __LINE__ << ": Could not open file 'X.dat'"
<< endl;
return false;
}
Could anybody tell me what's wrong with this code? I use gcc 3.3.1
under cygwin.
Thanks,
Joe
I wrote a program that uses ifstream to open an ASCII file and
getline() to read in the lines. The problem is when I try to open the
same file again later in the code. I used close() to close the file
but the next open() fails. If I comment out the getline() then I can
open it a second time without a problem. Here are parts of the code:
ifstream InputFile;
char Line[MAXcharLine + 1]; // MAXcharLine = 512
InputFile.open("X.dat");
if (InputFile == NULL)
{
cerr << "Error at " << __LINE__ << ": Could not open file 'X.dat'"
<< endl;
return false;
}
while (InputFile.getline(Line, MAXcharLine))
{
// STUFF
}
InputFile.close();
....
InputFile.open("X.dat");
// This here fails!
if (InputFile == NULL)
{
cerr << "Error at " << __LINE__ << ": Could not open file 'X.dat'"
<< endl;
return false;
}
Could anybody tell me what's wrong with this code? I use gcc 3.3.1
under cygwin.
Thanks,
Joe