简体   繁体   English

Xcode C ++可执行文件无法找到并打开.txt文件

[英]Xcode C++ executable file cannot find and open .txt files

I bulid my C+++ project use Xcode 8.2.1 and generate an executable file in Bulid folder. 我使用Xcode 8.2.1扩展了我的C ++项目,并在Bulid文件夹中生成了一个可执行文件。 But when I double click this file, it shows like this: 但是当我双击该文件时,它显示如下:

Last login: Mon Mar 13 16:27:59 on ttys001
RMBP:~ star$ /Users/mac/Documents/XCode/RCPSP/Build/Products/Release/RCPSP ; exit;
Cannot open file!
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.

I tried to put the executable file in the project's working directory, but it still didn't work. 我试图将可执行文件放在项目的工作目录中,但仍然无法正常工作。 Does anyone who knows how to fix it? 有谁知道如何修复它? I can't appreciate more. 我不能再欣赏了。 My code reads the .txt file like this 我的代码像这样读取.txt文件

ft=fopen("j30optima.txt","r");
    if(ft==NULL)
    {
        cout<<"Cannot open file!"<<endl;
        exit(1);
    }

I figured out the answer. 我想出了答案。 When I put all these txt files in /Users/mac folder, then double click the executable file, it works. 当我将所有这些txt文件放在/ Users / mac文件夹中时,然后双击可执行文件,它可以工作。 But why I must put these files in /Users/mac? 但是为什么我必须将这些文件放在/ Users / mac中? Can I change the setting? 我可以更改设置吗? I want to make the executable file work when I put these txt files and it together, just like how .exe files work under Windows OS. 当我将这些txt文件及其放在一起时,我想使可执行文件正常工作,就像.exe文件在Windows OS下的工作方式一样。

You executable is stored in a separate folder. 您的可执行文件存储在单独的文件夹中。 Double clicking the icon will not open the folder. 双击该图标将不会打开该文件夹。

The executable is stored in the debug folder. 可执行文件存储在调试文件夹中。 To open it right click the executable and click 'open in Finder' . 要打开它,请右键单击该可执行文件,然后单击“在Finder中打开” Note that if you create files in your program or want to access files in your program those will need to go in this debug folder along side the executable. 请注意,如果您在程序中创建文件或要访问程序中的文件,则需要将这些文件放在可执行文件旁边的调试文件夹中。

在取景器中显示

Edit: Build your program as debug. 编辑:构建您的程序作为调试。 Use the executable as shown above and put files in that directory too. 使用上面显示的可执行文件,并将文件也放置在该目录中。 When you want to release your program, make an .exe, you can use tools such as gpp to build all your files together. 当您要发布程序时,创建一个.exe,则可以使用诸如gpp之类的工具来一起构建所有文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM