Xcode File Stream Problem

maizen

Registered
I am having trouble with file i/o while using Xcode. My program is written in C++ and needs to read a file for input. I know my code works because it compiles correctly in CodeWarrior on a Win32 platform. I've tried putting the file to be read in every concievible place where Xcode may want to read the file (including the root folder, the folder which contains the source code file, the folder which contains the Xcode application, etc...). What can I do about this?

Thank you,
Matthew

The following is my code snippet:
Code:
    int      row;
    int      col;
    ifstream infile;


    infile.open("firstGenData.txt");


    assert(infile); // I know this is odd but it's
                    // what my instructor wanted

    infile >> row >> col;


    while (infile)
    {
        currGen[row][col] = '*';
        infile >> row >> col;
    }

    infile.close();
    infile.clear();
 

kainjow

Registered
I believe when you launch any program from Xcode, Xcode sets the app's working directory to something else, not what you would expect. So I don't believe it's looking for "firstGenData.txt" inside the app directory. However try executing your app normally, not from Xcode (just the Terminal) and see if it works then.
 

maizen

Registered
It does compile correctly using Terminal. I don't see a reason why the developers would make it do that, though. I added the file to the project in as many different directories as I could. I just don't get it. I even tried hard-coding where the file was from the root directory. There should be someplace that I can either set the folder where the program reads from or at least tells me where to put it. I really enjoy coding in Xcode, but it's a pretty big deal not to be able to compile programs that use the file stream correctly. Ugh.
 

Viro

Registered
The file should be in the folder Build->Debug/Release (depending on your build config, the default is Debug) located in your project folder. Put the file in either Debug or Release. That should make it work.
 
Top