The Xcode application no longer reads input from the folder. The application is stored in

The name is a bit outdated, but basically I wrote an application that reads and writes its input and output to text files. All the time he read and wrote files directly in the same directory as my data folder X-> code-> project-> build-> products-> debug. This was what everyone wrote and read about. I don't have a custom path for the application, so it just keeps wherever the application is. I first launched the Apple Instruments app to learn how to use the profiler. Shortly after selecting this application as the target in Tools, I returned to the Xcode application to run the program a bit more. Everything works fine in Xcode. It reads files and prints files in the same place as the folder, but if I try to start the program itself by clicking on the file and having the terminal open, it no longer reads and does not print in the directory in which the application is located. Instead, print it and read from my home folder. I don’t know what has changed or what has changed it, but I hope this is a simple solution. I would like the application to read files and print files from the directory in which it is located again. I'm not sure if this is his Xcode or Terminal setup.

Any help would be greatly appreciated.

Update 1: tried this with no luck:

how to change working directory to program location

The catalog field was empty, so I thought it was a solution, but filling it out with a sentence did not help to fix the problem.

Update 2:

Just tried to delete the settings file, but still no solution. I am ready to give someone a reputation. I don’t have much because I am a beginner, but I will give what a person considers fair to someone who decides it. I am desperate and really do not want to wait 2 days to solve this problem.

Update 3:

I tried to change the default path in the "Profile (release) β†’ parameters area in the schematic section to the default variable proposed in update 1. No luck. I'm starting to lose my mind.

Update 4:

I tried to completely remove the circuit and create a new one, hoping that maybe something is wrong with this circuit, but this did not solve the problem. Input and output when starting the application in Xcode still uses the working directory, and when you run the executable in the debug folder, the home folder is used.

Update 5:

Just tested this on an earlier installation of iMac and Xcode (OS 10.8.5 and Xcode 5.1.1) and it seems to work correctly, reading and writing to the current working directory of the application in the debug folder.

+6
source share
1 answer

For some reason, the solution offered by fooobar.com/questions/259205 / ... does not work anymore. Maybe broken in Xcode 8.1. But it works:

#include <iostream> #include <fstream> #include <unistd.h> using namespace std; int main (int argc, const char * argv[]) { // argv[0] returns the full path to the program, in my case "/Users/yuchen/Library/Developer/Xcode/DerivedData/../Debug/test string directory(argv[0]); // And we want to get rid of the program name `test` directory = directory.substr(0, directory.find_last_of("/")); // Point the directory to the program directory chdir(directory.c_str()); cout << "Current directory is: " << getcwd(NULL, 0) << endl; // /Users/yuchen/Library/Developer/Xcode/DerivedData/../Debug/ ifstream fin("hi.txt"); if (fin.is_open()) cout << "File is Open" << endl; else cout << "File is not open" << endl; fin.close(); return 0; } 

Also see fooobar.com/questions/259205 / ... and fooobar.com/questions/259205 / .... Hope this helps.

+1
source

Source: https://habr.com/ru/post/1012816/


All Articles