新的Xcode不能打开c ++中的文件? [英] New to Xcode can't open files in c++?

查看:983
本文介绍了新的Xcode不能打开c ++中的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用windows中的类,但我试图运行一个基本的代码,以了解如何打开/关闭/输入/输出从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;


}


推荐答案

将.txt文件放在main.cpp文件所在的目录(或任何你喜欢的目录)中。

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

在Xcode中转到产品>方案>编辑方案>运行测试(右侧)>选项(中间顶部)

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

在选项检查使用自定义工作目录下,将其设置为.txt文件所在的目录。

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

要使用文件将必须只指定文件名,例如in_file.open(inputFile.txt);没有路径是必要的。

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

这篇关于新的Xcode不能打开c ++中的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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