Xcode上C ++中的文件创建 [英] File creation in C++ on Xcode

查看:94
本文介绍了Xcode上C ++中的文件创建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这应该在我的项目目录中创建一个名为"tuna.txt"的文件.当我运行它时,它可以成功编译,但是没有创建文件.我在使用xcode的Mac上.我在计算机上搜索了可能已创建文件的其他位置,但似乎根本没有创建该文件.关于它为什么不起作用的任何想法?

This is supposed to create a file in my project directory called "tuna.txt". When I run it, it compiles successfully, however no file is created. I am on a mac using xcode. I have searched my computer for other places where it might have been created, but it seems as if the file was not created at all. Any ideas as to why it doesn't work?

#include <iostream>
#include <fstream>
using namespace std;
int main(void){
    ofstream file;
    file.open("tuna.txt");

    file << "I love tuna and tuna loves me!\n";
    file.close();
    return 0;
}

推荐答案

我向您保证,会创建一个限制错误(您无需检查的文件).从IDE运行时,Xcode倾向于使用最终的build-dir作为当前工作目录.您可以通过编辑活动的方案来更改此设置.

I assure you that barring errors (which you're not checking for) a file is created. Xcode has a tendency to use the final build-dir as the current working directory when running from the IDE. you can change this by editing the active Scheme.

  1. 单击主工具栏上停止"按钮右侧的项目"框
  2. 选择编辑方案
  3. 在左窗格列表中选择运行"子方案.
  4. 选择选项"标签,
  5. 选中使用自定义工作目录"复选框
  6. 将工作目录设置到您知道的某个位置(例如您的项目根文件夹).
  1. Click on the Project box to the right of the STOP button on the main toolbar
  2. Select Edit Scheme
  3. Select the "Run" sub scheme in the left pane list.
  4. Select the Options tab,
  5. Check the "Use Custom Working Directory" checkbox
  6. Set the working directory to some place you know (like your project root folder).

注意:如果需要,您还可以在此处设置任何命令行参数(这些参数位于参数"选项卡上,而不是选项"选项卡上.)

Note: This is also where you will setup any command line arguments (those are on the Arguments tab, not the Options tab), should you desire to do so.

这篇关于Xcode上C ++中的文件创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆