Trouble with Xcode file i/o using C ?

I'm using Xcode on my Mac to do projects in C++ for a class. My school uses Visual Studio, and for that program when you input or output to a file, it looks in the same folder where the .cpp file is located. But it appears that's not the case for Xcode.


My question is, is there a way to go into Xcode's preferences and change the directories somehow to make the file i/o directories the same as for Visual Studio? i.e., when I output a file, I want it to go into the same folder as the source code; and when I read a file I want it to look in that folder also.


Thank you very much for any help.

MacBook Pro with Retina display, OS X Mountain Lion (10.8.4)

Posted on Nov 17, 2013 12:32 PM

Reply
3 replies

Nov 17, 2013 1:07 PM in response to Suave Ruse

Xcode isn't doing anythring wrong. In any C++ program, the current directory is just wherever the current directory happens to be. It is never guaranteed. There are many options. You can hard-code the path. You can pass the path in a command-line argc/argv parameter. You can display an interface to ask the user for the file.


If you really want to, you can set the working directory in Xcode. Click on the application in the toolbar and choose "Edit scheme". Select the "Run" item. Select the "options" tab. Change "Working Directory" to something.

Nov 17, 2013 8:24 PM in response to Suave Ruse

It isn't something to be "fixed". It is something that one shouldn't do. Xcode is an IDE for building real applications. It simply isn't designed for reading text files in the current directory. If you aren't writing a GUI application, the proper way to do that is to get a parameter form the command line or, even better, read from standard input.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Trouble with Xcode file i/o using C ?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.