- Mar 31, 2003
- 11,679
- 0
- 81
Ok guys, I can't for the life of me figure out why this stupidly simple piece of C++ code isn't working.
The first file that it opens, it does so successfully. However, when attempting to open the second file, it outputs both "I'm open..." and "Just kidding". The getline() returns something that causes the entire while loop to test false and continue the entire loop.
Any ideas??
-Kevin
Edit: For further information -- If I start on the second file, that file opens and then the one immediately following that does not. It's like I'm allowed 1 open and close per program -_-
Code:
ifstream txtInFile;
for( theDay = 1; theDay <= 31; theDay++ )
{
stringstream txtInFileName( stringstream::in|stringstream::out );
cout << theDay << endl;
txtInFileName << "C:\\Documents and Settings\\KMBOYD\\Desktop\\Test\\";
txtInFileName << "d1_" << theYear;
if ( theMonth < 10 )
txtInFileName << "0";
txtInFileName << theMonth;
if ( theDay < 10 )
txtInFileName << "0";
txtInFileName << theDay;
txtInFileName << ".txt";
cout << "The fileName is " << txtInFileName.str() << endl;
txtInFile.open( txtInFileName.str().c_str(), ifstream::in|ifstream::beg );
if ( txtInFile.is_open() )
{
cout << "I'm open..." << endl;
}
if ( !txtInFile )
{
cout << "Just kidding..." << endl;
continue;
}
int lineNumber = 0;
while( getline( txtInFile, fileBuffer[lineNumber] ) )
{
if ( !strcmp( (fileBuffer[lineNumber].substr( 0, fileBuffer[lineNumber].find(' ')).c_str() ), "SDS" ) )
{
continue;
}
if ( fileBuffer[lineNumber].empty() )
{
continue;
}
lineNumber++;
}
txtInFile.close();
//Do stuff
}
The first file that it opens, it does so successfully. However, when attempting to open the second file, it outputs both "I'm open..." and "Just kidding". The getline() returns something that causes the entire while loop to test false and continue the entire loop.
Any ideas??
-Kevin
Edit: For further information -- If I start on the second file, that file opens and then the one immediately following that does not. It's like I'm allowed 1 open and close per program -_-
Last edited: