以编程方式确定工作目录的工作方式与往常一样,无论 IDE 是什么.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;} 解决方案 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 4 (C++) 中相对引用文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-03 06:19