我已经在网络和这里搜索了这个,但我似乎无法弄清楚我做错了什么。在我的代码中处理文件时遇到问题?
我只是想通过文件处理和C++获得更好的效果。
对于练习,我试图抓取游戏文件夹中的文本文件并复制它。
这是我的代码(不能访问该文件)。
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int main()
{
//define/open files
ifstream my_input_file;
ofstream my_output_file;
string filepath = "C:/Users/David Laptop/Documents/my games/oblivion/RenderInfo.txt";
my_input_file.open(filepath);
if (my_input_file.is_open())
{
cout << "opened\n";
my_output_file.open("output_file.txt", ofstream::trunc);
char c;
my_input_file.get(c);
while (my_input_file)
{
my_output_file.put(c);
my_input_file.get(c);
}
my_input_file.close();
my_output_file.close();
}
else
{
cout << "FAIL\n";
}
cin.get();
return 0;
}
这似乎与项目目录中的文本文件和.ini文件一起工作,但我遇到问题正确地转到其他directiorys?
任何想法?
谢谢!
什么具体不工作? – Carcigenicate
[在工作目录之外的C++中打开文件]可能的重复(http://stackoverflow.com/questions/10093891/opening-a-file-in-c-outside-of-the-working-directory) – eshirima
该文件没有被打开,因此没有被复制到output_file.txt中 –