
July 28th, 2006, 11:56 AM
|
 |
Business Analyst
|
|
Join Date: Mar 2004
Location: The 'Ville
|
|
|
File read/write problem
This is MFC code, but the core of it is just ifstream and ofstream. The file pattern I'm looking for in this test is c:\temp1\test*.txt and the CFileFind successfully finds each file. I get to the part that checks for both files to be open and they both are. The first iteration through I get test1.txt and it opens the file, reads it, and writes it to the output file, no problems. But when I get to the second and third files test2.txt and test3.txt it opens the files, both are open, but it never writes anything to the output file.
Basically it never enters the while loop for files 2 and 3. All three files contain multiple lines and carriage returns. Any ideas?
Thanks in advance!
Code:
bWorking = find.FindFile(csInputFile);
while(bWorking)
{
bWorking = find.FindNextFile();
if(csInputFile.CompareNoCase(csOutputFile) == 0 || bWildcard)
{
csTemp = find.GetFilePath() + _T(".bak");
rename((LPCTSTR) find.GetFilePath(), (LPCTSTR) csTemp);
}
else
{
csTemp = csInputFile;
}
// skip directories ('.' and '..')
if(!find.IsDots())
{
if(bWildcard)
{
csOutputFile = find.GetFilePath();
}
else
{
csOutputFile = csTemp;
csOutputFile.TrimRight(_T(".bak"));
}
fInput.open((LPCTSTR)csTemp, ios::in);
fOutput.open((LPCTSTR)csOutputFile, ios::out);
// this part works, both are open
if(fInput.is_open() != 0 &&
fOutput.is_open() != 0)
{
while(getline(fInput, s))
{
fOutput.write(s.c_str(), s.length());
}
// clean up
fInput.close();
fOutput.close();
}
else
{
bReturn = false;
}
}
}
__________________
Discontent is the first necessity of progress. - Edison
Last edited by mateoc15 : July 28th, 2006 at 12:06 PM.
|