如何在 Xcode 4 (C++) 中相对引用文件? [英] How to reference files relatively in Xcode 4 (C++)?

查看:16
本文介绍了如何在 Xcode 4 (C++) 中相对引用文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 C++ 项目,向项目添加了一个文本文件,现在我无法从中读取我记得在 XCode 3 中,Project 节点的 GetInfo 中有一个属性,用于设置相对于项目目录的构建和这使它起作用.

但在 XCode 4 中我找不到这样的设置或找到替代我只能引用具有绝对路径的文件.

#include 使用命名空间标准;int main (int argc, const char * argv[]){//这有效freopen("/Volumes/MyHD/XProjects/Test/File.txt", "r", stdin);//这不freopen("File.txt", "r", stdin);国际我;cin>>i;cout<<i;返回0;}

解决方案

您指的是可执行文件在运行时使用的工作目录吗?如果是这样,您可以通过编辑方案设置工作目录.

从 Schemes 弹出窗口中选择 Edit Scheme,然后从侧栏中选择 Run 操作.工作目录控件位于底部附近.选中使用自定义工作目录"框,然后单击文本字段右侧的小窗口/文件夹/卡片外观图标(我不知道他们在那里使用什么符号)并选择您的路径.

以编程方式确定工作目录的工作方式与往常一样,无论 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++) 中相对引用文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆