Code runs perfect in g++ but not in Xcode – Cannot find File

Your file fails to open because XCode launches from the IDE in the default build location, which is actually a temporary directory off somewhere on your disk. If you want change the working directory at launch-time to something else (like the location where your files can be found):

  1. Select the Product/Edit Scheme… menu option.
  2. Select the Run schema in the left list.
  3. At the bottom Options tab on the right pane should be a “Working Directory” option. Check the checkbox and set the custom working directory to someplace you know (your “/Users/yourname” home directory is a decent place that I use).
  4. Make sure any “current directory” data files you need for your program execution from the IDE are in this directory.

And in case you didn’t see it, this is also the place where you can configure command-line arguments (on another tab) of the same dialog.

Leave a Comment