XCode c++文件参考
我正在尝试编写一些算法程序来练习 Google Code Jam,但我无法让 XCode 从输入文件中读取(轻松)。
我已将该文件添加到项目中,它出现在左侧文件导航栏中。但我无法相对地引用它。在 Code::Blocks 中,我只是从“FileName.txt”输入,它可以工作,但使用 XCode 它就是找不到它。
如果我输入完整的文件路径(即 /Users/myname/Documents/Google Code Jam/ProjectName/ProjectName/FileName.txt),那么它可以工作,但这看起来很荒谬。
我可以做些什么来让 XCode 正常工作吗?添加文件时,我将复制文件勾选到项目目录中,并勾选了添加到目标可执行文件。
任何帮助表示赞赏。
谢谢!
I'm trying to write a few algorithm programs practising for Google Code Jam but I can't get XCode to read from an input file (easily).
I have added the file to the project and it appears in the left hand file navigation bar. But I can't reference it relatively. In Code::Blocks I just input from "FileName.txt" and it works but with XCode it just can't find it.
If I put the full file path (i.e. /Users/myname/Documents/Google Code Jam/ProjectName/ProjectName/FileName.txt) then it works but that just seems ridiculous.
Is there anything I can do to get XCode to work? When I added the file I ticked the copy file into project directory and also the add to target executable.
Any help is appreciated.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我刚刚发现了这个,Julio Gorgé 的评论正是我所需要的。在调试模式下运行时的默认工作目录是一些深奥的文件夹(正如您在 iOS 中看到的那样,如果您在 main() 的开头包含
system("pwd");
。它位于“ 编辑方案...菜单的“选项”选项卡,您可以勾选“使用自定义工作目录”并找到您在参数选项卡中放入的测试文件。
I just found this and the comments by Julio Gorgé is just what I needed. The default working directory when running in debug mode is some esoteric folder (as you can see in iOS if you include
system("pwd");
at the beginning of your main().It's in the "Options" tab of the Edit Scheme... menu that you can tick "Use custom working directory" and find the test file you put in in the Arguments tab.