REALLY simple Xcode question! Input File Stream!

Discussion in 'Mac Programming' started by HolyKiwi, Mar 26, 2008.

  1. macrumors newbie

    Mar 26, 2008
    I'm a comp sci major in college, and our default programming at school/home online console has got to be around 15+ years old now. I was tired of using it due to extreme lag... and started using XCode.

    I'm past learning how to open files with C++, but our current assignment requires that one be open. What do I need to do to the file in XCode/Where do I need to put it so that my program can open it? Does it have to be in a specific folder or anything?

    The file to be opened is Inventory.txt, and it's in the exact same folder as all the other .cpp and .h files. My coding for opening the program is flawless, as it works on the school's remote desktop'd unix, but at home I get the standard "Cannot open Inventory.txt!" that I added.

    I'm using C++ Tool under command line utility.
  2. macrumors regular


    Oct 19, 2005
    hmmm. I don't have a lot of experience developing on a mac. But, maybe its a permissions issue? Make sure your program will have permission to the file, maybe just chmod 777 it from the terminal.

    I would think if the file is with the compiled code (which may be in a different place than your source files) it should be able to open it otherwise.
  3. macrumors 68040


    Jan 10, 2005
    Dallas, TX
    If you don't have an explicit path to the file, then it will look in the working directory of the program. I'm not sure what directory Xcode executes your program from, but it may be in some sort of build directory. There are probably options for that in the project setup.

  4. macrumors 6502a

    Dec 4, 2006
    Katy, Texas
    The directory that will be used depends on your Build setting. If you have Debug set, the default working directory is


    If your setting is release, it will be


  5. macrumors 6502a

    Sep 3, 2005
    Cramlington, UK

    Select your program under Executables in Groups & Files and then get info (cmd I). You'll see where the default directory is set to, or you can change it to what you want.

    b e n
  6. macrumors newbie

    Sep 28, 2008
    Any success?

    I'm in a similar situation, and wherever I place the input text file and however I fiddle with the working directory setting for the app, it seems to make no difference. Very odd. It looks like "Users/.." for ever:confused:
  7. macrumors G5


    Nov 25, 2005
    Try a full path, like "/Users/yourname/whatever". The "/" at the beginning would be important.

Share This Page