Error Opening multiple files

B

BB

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::eek:ut||ios::binary);

//read in data
//...

for(int i = 0;i < 27;i++)
wFileOut<<i;


wFileIn.close();
wFileOut.close();


}


}
_findclose( hSearch );
exit(0);

Thanks
 
D

David Harmon

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::eek:ut||ios::binary);

if (!wFileOut)
perror(wOut);
 
D

David Harmon

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;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,188
Latest member
Crypto TaxSoftware

Latest Threads

Top