By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,406 Members | 888 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,406 IT Pros & Developers. It's quick & easy.

Error Opening multiple files

P: n/a
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::out||ios::binary) ;

//read in data
//...

for(int i = 0;i < 27;i++)
wFileOut<<i;
wFileIn.close();
wFileOut.close();
}
}
_findclose( hSearch );
exit(0);

Thanks
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Sat, 20 Dec 2003 15:56:04 -0000 in comp.lang.c++, "BB"
<ma******@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);

Jul 22 '05 #2

P: n/a
On Sat, 20 Dec 2003 17:31:43 GMT in comp.lang.c++, David Harmon
<so****@netcom.com> was alleged to have written:
On Sat, 20 Dec 2003 15:56:04 -0000 in comp.lang.c++, "BB"
<ma******@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;
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.