Benches MacBooks

9

Xcode debug mode and fstream problem

apple Verified

Imported from the Apple Support Forums via the Wayback Machine 🔗

I am having a problem with xcode 3.2.1 not being able to correctly read values from a file when set to debug mode. The program runs fine in release mode but in debug mode it reads in garbage values. If i make a standard c++ project in xcode and run the code below it exhibits the incorrect behavior.

#include <iostream>
#include <fstream>
int main (int argc, char * const argv[]) {

double var;
std::ifstream InitPositionFile;

InitPositionFile.open("Numbers.txt");

InitPositionFile >> var;

std::cout<<var<<std::endl;

InitPositionFile.close(); // Close File

return 0;
}

Any idea why the code only runs correctly in release mode?

9 replies

Sign in or join Beachball Help to reply.

  1. 0

    xnav

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Numbers.txt is not being found, specify the full path. It works in release because the execution path is the same as the path for Numbers.txt.

  2. 0

    squier

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    The file is being found, I just posted a stripped down version for testing. In the actual code I use the full path and check to see if the file is open before preceding.

    #include <iostream>
    #include <fstream>
    int main (int argc, char * const argv[]) {

    double var;
    std::ifstream InitPositionFile;

    InitPositionFile.open("/Users/Atrain/Desktop/Test/Numbers.txt");
    if (!InitPositionFile.is_open()){
    std::cout << "Could Not Open Position File"<<std::endl;
    exit(EXIT_FAILURE);
    }

    InitPositionFile >> var;

    std::cout<<var<<std::endl;

    InitPositionFile.close(); // Close File

    return 0;
    }

    If Numbers.txt contains a single number, in release mode the program will print out that number. In debug mode it prints out 0.

  3. 0

    ericmeyers

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Yup, you've hit a bug Apple still hasn't fixed.

    Remove
    GLIBCXXDEBUG=1
    GLIBCXX_DEBUGPEDANTIC=1 from the Debug build settings.

    Eric

  4. 0

    squier

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Thanks a lot! This has been driving me crazy.

  5. 0

    ericmeyers

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    No problem. It boggles the mind they've let it go on this long. If they can't fix the STL they could at least not set those defines.

    Eric

  6. 0

    dckap

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Hi,

    My code only works in debug mode and not in other modes. Any idea?

  7. 0

    etresoft

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    dckap wrote:

    Any idea?

    Yes! Create your own topic for the issue, add your source code, and we'll look at it.

  8. 0

    jwsang

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Where do you find these environment variable settings? Are they in a file somewhere?

    Curiously, I have this problem on a 17" Macbook Pro, but not on a fairly new MacBook Air.

  9. 0

    etresoft

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    They aren't environment settings. They are Xcode build settings.