Where does Xcode create .txt files to?
Asked Answered
D

11

6

http://www.cplusplus.com/doc/tutorial/files/

I just finished executing this but I didn't get any file on my desktop.

So where does the .txt file get placed on my computer?

// basic file operations
#include <iostream>
#include <fstream>
using namespace std;

int main ()
{
    ofstream myfile;
    myfile.open ("example.txt");
    myfile << "Writing this to a file.\n";
    myfile.close();
    return 0;
}
Dyak answered 4/11, 2012 at 3:51 Comment(2)
Out of interest, why did you expect it to be on your desktop?Pistil
From your profile - I am obsessed with being super efficient at all times. So, did my answer solve your problem?Pistil
R
15

Damn... I've seen this post never answered many times..

Here's the solution

In your project navigator when you're working in your current project there are many files. Try products (if I remember) and look for the executable file. Now go to the properties inspector or whatever is called. (Right side of your Xcode.)

There you will find somewhere a part called PATH the path that is written over there. It's the path where the executable runs. That means there is where you'll find all the files you create with your program.

Try it... that's how I manage and look my .txt files since sometimes I wanna give them some kind of formatting.

I hope I've solved your problem... cheers! ;)

Reflexive answered 16/1, 2013 at 23:56 Comment(0)
S
7

Click on the executable in the Products tab on the left hand side, and you should see the path to it displayed on the right in the utilities section. This is where they are saved. On my computer this path is:

/Users/myName/Library/Developer/Xcode/DerivedData/CurrentXcodeProject-adsnvetbleazktcgitfymfcbhkkt/Build/Products/Debug/filename.txt

Stocktaking answered 15/5, 2014 at 10:26 Comment(0)
P
3

In the "current directory", meaning the working directory of the environment from which you ran the executable.

I can't tell you what that is, but in basic cases it may be the directory where the executable is located. In many other cases it may not be.

Performing a search for the file on your hard drive will reveal its location to you.

Pistil answered 4/11, 2012 at 3:53 Comment(6)
@bryanmac: My answer doesn't claim that he is.Pistil
When I commented it did - you said Windows explorer and changed it to hard drive. Anyways, details. I think your answer of current directory is correct .. +1Lipophilic
@bryanmac: You must have imagined it! :)Pistil
@LightnessRacesinOrbit I am using Xcode on a Mac. I expected the file to land on my Desktop because all of the tutorials I watch indicate that is where it will reside. Everyone else uses Visual Studio and a PC. There are small differences between Xcode and Visual Studio (for one) to understand as well as the language itself. I have searched for it and I usually get a phone book's worth of files that I don't want to manually search. I guess I don't understand what "Current Directory" means. Is it where the .exe file lives or the .cpp or what?Dyak
@Josh: Not necessarily either. It's the current directory of the shell that executed the program, a property that exists even when you as a user actually executed the program from some GUI -- the GUI is, under the hood, still running over a shell. In Windows you can set the "Run in" property on shortcuts to change this; I wouldn't know about OSX. The IDE you used to compile the code isn't really relevant.Pistil
FWIW you get a "phone book's worth of files" because programming is very complicated, and it's worth you taking the time to read up about it properly rather than skimming through. Relying on tutorials on the internet and copy/pasting their code into your applications is rather akin to picking chewing gum off the street and eating it.Pistil
W
2

Right click on your product and select "Show in Finder". Thats opens the path to where the output files go. Also you can add input files there to be read in by your program.

Walkabout answered 9/4, 2015 at 3:31 Comment(0)
D
1

Found best answer here: File creation in C++ on Xcode

Basically you can specify a known directory so that all files created go there.

Durrace answered 22/1, 2014 at 12:36 Comment(0)
A
1

If you are on Mavericks Right click in your user folder with your documents and pictures and stuff (~/Users/yourusername) Now right click and view options. Check "show library". Now follow to the path that the first user above said.

Affidavit answered 7/3, 2014 at 22:28 Comment(0)
S
0

What I've always done when an application saves a file and I don't know where... is just go back to that application, and hit File>Save As...

So re-open Xcode and go to the "File" menu, and click "Save As..."

It will show you the same directory it just saved to.

Snot answered 4/11, 2012 at 4:6 Comment(1)
Thanks for the tip. I am looking for the default location though. I am wondering if I can change it too.Dyak
D
0

I have checked the "Current Directory" but I believe I have to specify the location. Not even

~User/Desktop 

will work.

What I do is create an empty file with a the correct name on my desktop then drag that file into my Xcode project to get its path. I then delete the file.

Same with adding files to my project. I can add them from the File menu, but I will need to drag them in to the spot in my code where I want to reference them.

It is kind of convoluted but it is the only system I have.

Dyak answered 20/11, 2012 at 19:51 Comment(0)
I
0

Some of the answers are confusing. Here's the simplest solution. 1. Expand your Products folder on the left-hand side 2. Right click on the terminal icon(sorry I do not know what it's called) 3. Click show in Finder. You should be able to see your output file in there.

Intelligence answered 2/9, 2015 at 0:3 Comment(0)
F
0

" Where does Xcode create .txt files to? "

You can decide where you want: follow these->

  1. " Product->Scheme->EditScheme "
  2. chose options tab in the new popup "options"
  3. "working directory" tick "use coatroom working directory" and locate the folder where you want.

The .txt file that you "create", or that you want too "read" has to keep in this folder.

Frierson answered 7/9, 2015 at 17:37 Comment(0)
E
0

In 2022, click on the project name in the "breadcrumbs" area above the editor. Select the correct thing in "Products", then in the right area, see "Full Path".

Ellette answered 26/8, 2022 at 14:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.