how to access a text file while debugging with eclipse CDT

前端 未结 5 1797
刺人心
刺人心 2020-12-21 04:16

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())
{
             


        
相关标签:
5条回答
  • 2020-12-21 04:30

    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.

    0 讨论(0)
  • 2020-12-21 04:42

    After deselecting the use default button, select the folder containing your binary file. The binary file can be found under Run configurations > Arguments > working directory.

    0 讨论(0)
  • 2020-12-21 04:43

    Write a test program that creates file, such as "Here_I_Am.txt".

    The directory where this is found will be the directory that the executable is using as the default directory.

    Add paths to your filename as appropriate, relative to the "Here_I_Am.txt" file. Or put your text file in the same directory as "Here_I_Am.txt"

    0 讨论(0)
  • 2020-12-21 04:54

    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.

    0 讨论(0)
  • 2020-12-21 04:55

    I found that with Eclipse, having the file in the root directory of the project should let it load. However, if you want to run it from the command line, the file needs to be in the same folder as the executable (something like Debug/ inside the project folder).

    It should work to drag and drop the file into your Eclipse project. Just make sure that you select the option to Copy the file, rather than Link to it.

    0 讨论(0)
提交回复
热议问题