# Xcode File Stream Problem



## maizen (Aug 19, 2005)

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:

```
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 (Aug 21, 2005)

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 (Aug 24, 2005)

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 (Aug 26, 2005)

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.


----------



## boyfarrell (Aug 27, 2005)

How does Viro always know what to do!   

(I had the same problem)   

Cheers yet again!


----------

