如何在使用eclipse CDT调试时访问文本文件 [英] how to access a text file while debugging with eclipse CDT
问题描述
我编写此代码以访问eclipse CDT中的文件
I am writing this code to access a file in eclipse CDT
ifstream inFile;
ofstream outFile;
string next;
inFile.open("input.txt");
if (inFile.fail())
{
cout << "\nCould not open input.txt";
exit(1);
}
问题是当我尝试调试我的应用程序或运行我的应用程序从eclipse里面找不到input.txt文件。当我从控制台运行我的应用程序工作正常,并打开文件。我需要调试应用程序,但不能,因为某种原因eclipse ide无法找到该文件。
the problem is when I try to debug my app or run my app from inside eclipse it cannot find the input.txt file. When I run my app from the console it works fine and opens the file. I need to debug the app but can't because for some reason the eclipse ide cannot find the file.
我应该把文件放在哪里?
Where should I put the file?
推荐答案
这可能是相对路径的问题。在您的项目的根目录中是否 input.txt
? Eclipse使项目的顶级目录成为工作目录。如果用完全限定的文件名替换代码中的input.txt
,那也应该可以。
It could be an issue with relative paths. Is input.txt
in the root directory of your project? Eclipse makes the top-level directory of the project the working directory. If you replace "input.txt"
in your code with the fully qualified file name, that should also work.
这篇关于如何在使用eclipse CDT调试时访问文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!