【发布时间】:2014-06-19 17:50:12
【问题描述】:
我一直在学习的课程中使用 windows,但我正在尝试运行一个基本代码来弄清楚如何从 Xcode 上的文件中打开/关闭/输入/输出以及我通常在视觉上使用的代码工作室不知道为什么?谢谢!
#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;
}
【问题讨论】:
-
也 #include
它没有复制...无论哪种方式我的输出都是“文件无法打开。” -
inputFile.txt在哪里? -
尝试指定文件的绝对路径。 XCode 在您的源代码所在的另一个位置执行,因此假设源目录的相对路径将不起作用。
-
欢迎来到 Xcode。你会找到this answer helpful,我几乎可以肯定。