Error Opening multiple files

Discussion in 'C++' started by BB, Dec 20, 2003.

  1. BB

    BB Guest

    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
     
    BB, Dec 20, 2003
    #1
    1. Advertising

  2. BB

    David Harmon Guest

    On Sat, 20 Dec 2003 15:56:04 -0000 in comp.lang.c++, "BB"
    <> 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::eek:ut||ios::binary);


    if (!wFileOut)
    perror(wOut);
     
    David Harmon, Dec 20, 2003
    #2
    1. Advertising

  3. BB

    David Harmon Guest

    On Sat, 20 Dec 2003 17:31:43 GMT in comp.lang.c++, David Harmon
    <> was alleged to have written:
    >On Sat, 20 Dec 2003 15:56:04 -0000 in comp.lang.c++, "BB"
    ><> 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;
     
    David Harmon, Dec 20, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brad
    Replies:
    5
    Views:
    555
  2. Replies:
    4
    Views:
    984
    M.E.Farmer
    Feb 13, 2005
  3. Error with threads opening files

    , Feb 28, 2010, in forum: C Programming
    Replies:
    4
    Views:
    305
    Ben Bacarisse
    Feb 28, 2010
  4. fniles
    Replies:
    0
    Views:
    290
    fniles
    Apr 26, 2009
  5. Subhabrata
    Replies:
    5
    Views:
    401
    Steven D'Aprano
    Jul 12, 2012
Loading...

Share This Page