xcode and input files

Discussion in 'Mac Programming' started by CaptainHat, Mar 8, 2007.

  1. macrumors newbie

    Joined:
    Mar 8, 2007
    #1
    Hi,

    I am trying to get a C++ tool to just read an input file and I added the file to the project, but whenever I try to open the file with

    ifstream infile( "input.txt" );

    it fails to open correctly. i.e., infile evaluates to false.

    Ideas anyone?

    thanks much.
     
  2. macrumors 6502a

    bbarnhart

    Joined:
    Jan 16, 2002
    Location:
    Stilwell, Kansas
    #2
    Does the filename need to be fully qualified?

    "/Users/CaptainHat/Documents/input.txt"

    Or, is "input.txt" in the same directory as the app?
     
  3. thread starter macrumors newbie

    Joined:
    Mar 8, 2007
    #3
    i just had "input.txt" , I copied the line from the source file into the original post.

    I ended up giving the thing an explicit complete path, "/Users/.../input.txt" and this ended up working, but it's kind of annoying in any event.

    Does anyone know how to set up Xcode so that if will look for input files in the same directory as the source code? This would a useful thing to know. I tried looking at the Build options in the help but this wasn't so easy to get through.

    Thanks.
     
  4. macrumors 6502a

    bbarnhart

    Joined:
    Jan 16, 2002
    Location:
    Stilwell, Kansas
    #4
    "./input.txt"?
     
  5. macrumors 6502a

    Joined:
    Sep 3, 2005
    Location:
    Cramlington, UK
    #5
    You can set the working directory for your executable in the 'General' tab in the info window for the executable. To get this window select 'Edit Active Executable' under 'Projects' in the menu bar. Just set it to whatever you want.

    b e n
     
  6. thread starter macrumors newbie

    Joined:
    Mar 8, 2007
    #6
    Thanks.
     
  7. macrumors 68000

    Soulstorm

    Joined:
    Feb 1, 2005
    #7
    You can also change the current working directory using C++ itself. You should use the system() command to do that. And then, give inside the command whatever you would give inside a terminal shell to change the current working directory.
     
  8. macrumors member

    Joined:
    Feb 18, 2007
    Location:
    Eindhoven
    #8
    Or directly using chdir (const char *filename) :)

    Wittegijt
     

Share This Page