DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: C++ Builder 6 fstream problem

  1. #1
    Join Date
    May 2009

    C++ Builder 6 fstream problem

    Here is the code

    std::ifstream releaseLog("ReleaseLog.txt");
    std::ofstream outName("GGGG.txt");

    if (releaseLog){

    The program creates GGGG.txt in the same folder where ReleaseLog.txt is however the if statement is never executed and I don't see why. Any help would be appreciated. (The ofstream works!)

  2. #2
    Join Date
    Nov 2003
    check the status of the file.
    It's better to create an empty ifstream object and then call open() exclusively. This will enable you to examine the return code and see what went wrong:
    std::ifstream releaseLog;
    Danny Kalev

  3. #3
    Join Date
    Dec 2007
    open() on a file stream returns void.
    you could check the status with rdstate()
    std::ifstream releaseLog( "ReleaseLog.txt" ) ;
    std::ios_base::iostate state = releaseLog.rdstate() ;
    to check for success, this is equally good:
    std::ifstream releaseLog( "ReleaseLog.txt" ) ;
    // ...
    if (releaseLog)
        // ...
    it appears that the file "ReleaseLog.txt" is not in the current directory.
    verify this by first deleting "GGGG.txt" and re-running the program to see where it is getting created.

  4. #4
    Join Date
    Nov 2003
    Yeah, open returns void, which is pretty silly I must say.
    Anyway, you can also use the bad() member function to see if there is a problem with the file stream object. Most likely, the file is located at a different directory so you can use its absolute path instead of just the filename.
    Danny Kalev

  5. #5
    Join Date
    Oct 2007
    IMO, the if-block is OK as written. Just add an else that examines rdstate() and whatever else to see what went wrong.

Similar Threads

  1. ActiveX problem using VB
    By koraal in forum VB Classic
    Replies: 3
    Last Post: 11-03-2006, 04:50 PM
  2. Problem with creating Multiple instances of Form in VB!
    By vb_programmer in forum VB Classic
    Replies: 16
    Last Post: 06-23-2006, 08:10 AM
  3. Josephus Problem, problem.
    By aesoprock00 in forum Java
    Replies: 2
    Last Post: 01-28-2006, 07:18 PM
  4. Replies: 0
    Last Post: 12-13-2001, 01:06 PM
  5. Get info from a Power Builder DataWindows
    By Javier Vargas in forum VB Classic
    Replies: 0
    Last Post: 11-01-2000, 09:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center