简体   繁体   中英

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. 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

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. But why I must put these files in /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.

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' . 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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