xcode and input files

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

  1. macrumors newbie


    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


    Does the filename need to be fully qualified?


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

    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.

  4. macrumors 6502a


  5. macrumors 6502a

    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. macrumors newbie

  7. macrumors 68000


    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

    Or directly using chdir (const char *filename) :)


Share This Page