Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New to Xcode can't open files in c++?

Tags:

c++

xcode

I've been using windows in a class I've been taking but I am trying to run a basic code to figure out how to open/close/input/output from files on Xcode and the code I usually use on visual studios isn't working any idea why? thanks!

#include <string> #include <iostream> #include <fstream> using namespace std;  int main() {     ifstream fin;     ofstream fout;     string input;      fin.open("inputFile.txt");     if(fin.fail())         cout << "File failed to open." << endl;     fin >> input;      fout.open("outputFile.txt");      fout << input;   } 
like image 672
user3473255 Avatar asked May 02 '14 23:05

user3473255


People also ask

How do I allow Xcode to open files?

Under Product , right click on the output program(not the product folder), and click Show in Finder , then drag the program into Full Disc Access or Files and Folders from earlier. Worked.

How do I fix Xcode file not found?

Delete the files from the xcode project navigator (only deleting references). Add them again to the project (dragging from finder into the project navigator).

How do I use text files in Xcode?

To add a text file to the project, right-click on the project folder in the project view in the left pane and select the option New Item... In the dialog that appears, select the Other category and the Empty file option. Name the file numbers. txt.


1 Answers

Put your .txt files in the same directory where your main.cpp file is (or anywhere you like).

In Xcode go to Product > Scheme > Edit Scheme > Run test (on the right) > Options (middle top)

Down under Options check “Use custom working directory” and set it to the directory where you .txt files are located.

To work with the files, you will have to specify just file names, e.g. in_file.open("inputFile.txt"); no path is necessary.

like image 167
nepete Avatar answered Sep 18 '22 22:09

nepete