简体   繁体   English

Xcode create.txt 文件在哪里?

[英]Where does Xcode create .txt files to?

http://www.cplusplus.com/doc/tutorial/files/ 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?那么 .txt 文件放在我电脑的什么位置呢?

// 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;
}

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.) (Xcode的右侧。)

There you will find somewhere a part called PATH the path that is written over there. 在那里你会找到一个名为PATH的部分,就是在那里写的路径。 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. 尝试一下......这就是我管理和查看我的.txt文件的方式,因为有时我想给他们一些格式。

I hope I've solved your problem... cheers! 我希望我已经解决了你的问题......干杯! ;) ;)

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

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. 在硬盘驱动器上执行搜索将显示其位置。

Right click on your product and select "Show in Finder". 右键单击您的产品,然后选择“在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. 您还可以在那里添加输入文件以供程序读取。

Found best answer here: File creation in C++ on Xcode 在这里找到最佳答案: 在Xcode上用C ++创建文件

Basically you can specify a known directory so that all files created go there. 基本上,您可以指定一个已知目录,以便创建所有文件。

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. 如果你在小牛队右键单击你的用户文件夹中的文件和图片和东西(〜/ Users / yourusername)现在右键单击并查看选项。 Check "show library". 检查“显示库”。 Now follow to the path that the first user above said. 现在按照上面第一个用户说的路径。

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..." 所以重新打开Xcode并转到“文件”菜单,然后单击“另存为...”

It will show you the same directory it just saved to. 它将显示刚刚保存到的目录。

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. 我所做的是在桌面上创建一个具有正确名称的空文件,然后将该文件拖到我的Xcode项目中以获取其路径。 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. 我可以从“ File菜单中添加它们,但我需要将它们拖到我想要引用它们的代码中的位置。

It is kind of convoluted but it is the only system I have. 它有点复杂,但它是我唯一的系统。

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. 1.展开左侧的Products文件夹2.右键单击终端图标(抱歉,我不知道它的名称)3。单击Finder中的show。 You should be able to see your output file in there. 您应该能够在那里看到您的输出文件。

" Where does Xcode create .txt files to? " “Xcode在哪里创建.txt文件?”

You can decide where you want: follow these-> 您可以决定您想要的位置:按照这些 - >

  1. " Product->Scheme->EditScheme " “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. “工作目录”勾选“使用coatroom工作目录”并找到所需的文件夹。

The .txt file that you "create", or that you want too "read" has to keep in this folder. 您“创建”的.txt文件或您想要“读取”的文件必须保留在此文件夹中。

In 2022, click on the project name in the "breadcrumbs" area above the editor. 2022,在编辑器上方的“面包屑”区域点击项目名称。 Select the correct thing in "Products", then in the right area, see "Full Path". Select 在“产品”中正确的东西,然后在右侧区域,请参阅“完整路径”。

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

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