C++ Xcode 在哪里创建 .txt 文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13215910/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 17:05:42  来源:igfitidea点击:

Where does Xcode create .txt files to?

c++filelocation

提问by Josh Smith

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

回答by SuEric

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

在那里你会找到一个叫做PATH路径的部分,它写在那里。这是可执行文件运行的路径。这意味着您可以在那里找到您使用程序创建的所有文件。

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

试试看……这就是我管理和查看.txt文件的方式,因为有时我想给它们某种格式。

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

我希望我已经解决了你的问题......干杯!;)

回答by Tyler

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

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

回答by Lightness Races in Orbit

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.

搜索硬盘驱动器上的文件将向您显示其位置。

回答by SSB

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.

右键单击您的产品并选择“在 Finder 中显示”。这将打开输出文件所在的路径。您也可以在那里添加输入文件以供您的程序读入。

回答by user3223492

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.

基本上,您可以指定一个已知目录,以便创建的所有文件都在那里。

回答by user3223492

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.

如果您在 Mavericks 上右键单击您的用户文件夹,其中包含您的文档、图片和内容 (~/Users/yourusername) 现在右键单击并查看选项。选中“显示库”。现在按照上面第一个用户说的路径。

回答by user2649966

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.

有些答案令人困惑。这是最简单的解决方案。1. 在左侧展开您的产品文件夹 2. 右键单击​​终端图标(抱歉我不知道它叫什么) 3. 在 Finder 中单击显示。您应该能够在那里看到您的输出文件。

回答by user2649966

" Where does Xcode create .txt files to? "

“ Xcode 在哪里创建 .txt 文件?“

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.
  1. “产品->方案->编辑方案”
  2. 在新弹出的“选项”中选择选项选项卡
  3. “工作目录”勾选“使用衣帽间工作目录”并找到您想要的文件夹。

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

您“创建”的 .txt 文件或您想要“阅读”的 .txt 文件必须保留在此文件夹中。

回答by millertime

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.

它将向您显示刚刚保存到的同一目录。

回答by Josh Smith

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.

我所做的是在桌面上创建一个具有正确名称的空文件,然后将该文件拖到我的 Xcode 项目中以获取其路径。然后我删除文件。

Same with adding files to my project. I can add them from the Filemenu, 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.

这有点令人费解,但它是我拥有的唯一系统。