How to reference files relatively in Xcode 4 (C++)?
I have a c++ project, add a text file to the project, now I can't read from it I remember in XCode 3 there was property in GetInfo of the Project node, to set the build relative to the project directory and that made it work.
But in XCode 4 I can't fi开发者_开发知识库nd such setting or find a substitute I can only reference files if they are with absolute paths.
#include <iostream>
using namespace std;
int main (int argc, const char * argv[])
{
//This works
freopen("/Volumes/MyHD/XProjects/Test/File.txt", "r", stdin);
//This doesn't
freopen("File.txt", "r", stdin);
int i;
cin>>i;cout<<i;
return 0;
}
Are you referring to the working directory the executable uses when run? If so, you can set the working directory by editing the scheme.
Choose Edit Scheme from the Schemes popup, then choose the Run action from the side bar. Working Directory controls are near the bottom. Check the "Use custom working directory" box then click the little window/folder/card-looking icon (I have no idea what symbol they're going for there) in the right side of the text field and choose your path.
To determine the working directory programmatically works the same as it always has, regardless of the IDE.
Xcode 5: menu bar > Product > Scheme > Edit Scheme...
Note: This Answer is in reply to the following comment because I don't have enough reputation to reply to comment above:
Where is the "Scehemes Popup"? – aaronsnoswell Nov 28 '13 at 1:51
精彩评论