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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With