Thread: fstream questions!

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User Terran's Avatar
    Join Date
    May 2008
    Location
    Nashua, NH
    Posts
    100

    fstream questions!

    So in the constructor for my class, i want it to check to see if the list file is there list.bin if so i want it to open it, else wise, i'd like it to create it. I also want it to ignore it if it's empty, but it doesn't seems to work.

    Code:
        std::ifstream fin("list.bin", ios::binary); //open it to read? Can this also create it?
        if (!fin){ // if it doesn't exist? this works.
            wxMessageBox("File Function Failed!"); 
        }
        else {  // if it exists...
            if(!fin.eof()){ // .. but what if it's empty?
                wxMessageBox("NOT EMPTY!"); // this happens with a seemingly empty file!
                
            }
            else {
                wxMessageBox(" EMPTY!"); 
                fin.close(); // this is in the wrong place, ignore it!
            }
        }
    Last edited by Terran; 07-04-2008 at 05:47 PM.
    Sorry, but i'm a Code::Blocks man now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 05:36 AM
  2. Trivial questions - what to do?
    By Aerie in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 12-26-2004, 09:44 AM
  3. ARGH! fstream errors
    By OttoDestruct in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2004, 10:37 PM
  4. Are fstream and ofstream incompatible?
    By johnnyd in forum C++ Programming
    Replies: 5
    Last Post: 03-19-2003, 12:21 PM
  5. Problems with fstreams.
    By mosdef in forum C++ Programming
    Replies: 7
    Last Post: 06-19-2002, 03:36 PM