Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to access a text file while debugging with 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);

}

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?

like image 369
Letholdrus Avatar asked Dec 10 '22 06:12

Letholdrus


2 Answers

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.

like image 86
Daniel Avatar answered Mar 25 '23 04:03

Daniel


Other than moving your source input file, you may consider changing the working directory for launching the application.

By setting "Run Configurations" > [The RUN] > "Arguments" Tab > "Working directory" from "${workspace_loc:[Project Name]}" to something else like "${workspace_loc:[Project Name]}/Release", which is the usual binary target directory for Eclipse would do.

like image 42
Dominic Hung Avatar answered Mar 25 '23 04:03

Dominic Hung