How to reference files relatively in Xcode 4 (C++)?

橙三吉。 提交于 2019-12-23 02:28:27

问题


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 find 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;
}

回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/5769314/how-to-reference-files-relatively-in-xcode-4-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!