Error Opening multiple files



 DEVELOP > c-Plus-Plus > Error Opening multiple files

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "BB"
Date: 20 Dec 2003 09:56:04 AM
Object: Error Opening multiple files
Im trying to write a piece of code to open all files in the current
directory, read their contents and write it out to another file.
However after the program runs the output files are not there. Through
debugging I know the (output)files are being opened and the info. is being
wrote to them. But there is no files anywhere when the program finishes??
A piece of code used:
while( _findnext( hSearch, &FileData ) == 0 )
{
cout<<"FILE "<<FileData.name;
wFileIn.clear();
wFileIn.open(FileData.name,ios::in||ios::binary);
if(!wFileIn.is_open())
{
cout<<"File "<<FileData.name<<" could not be opened"<<endl;
}
else
{
getOutputFile(FileData.name,wOut);//gets the name of output file
wFileOut.clear();
wFileOut.open(wOut,ios::in||ios::out||ios::binary);
//read in data
//...
for(int i = 0;i < 27;i++)
wFileOut<<i;
wFileIn.close();
wFileOut.close();
}
}
_findclose( hSearch );
exit(0);
Thanks
.

User: "David Harmon"

Title: Re: Error Opening multiple files 20 Dec 2003 11:31:43 AM
On Sat, 20 Dec 2003 15:56:04 -0000 in comp.lang.c++, "BB"
<mahdlahd@eircom.net> was alleged to have written:

wFileIn.open(FileData.name,ios::in||ios::binary);
if(!wFileIn.is_open())
{
cout<<"File "<<FileData.name<<" could not be opened"<<endl;

if (!wFileIn)
perror(Filedata.name);

getOutputFile(FileData.name,wOut);//gets the name of output file
wFileOut.clear();
wFileOut.open(wOut,ios::in||ios::out||ios::binary);

if (!wFileOut)
perror(wOut);
.
User: "David Harmon"

Title: Re: Error Opening multiple files 20 Dec 2003 11:37:34 AM
On Sat, 20 Dec 2003 17:31:43 GMT in comp.lang.c++, David Harmon
<source@netcom.com> was alleged to have written:

On Sat, 20 Dec 2003 15:56:04 -0000 in comp.lang.c++, "BB"
<mahdlahd@eircom.net> was alleged to have written:

wFileIn.open(FileData.name,ios::in||ios::binary);

Oops, did not spot that the first time through!
Should be:
wFileIn.open(FileData.name, ios::in|ios::binary);
Use | for or-ing bits and flags.
Use || for or-ing true false bools;
.



  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER