0

I have SOME_TEXT.TXT in the Debug folder for my project. When I manually go to the Debug folder and run the application, I get the expected output and all is glorious. However, when I Debug the app within Visual Studio txtFile.is_open() fails and my output doesn't work. I've looked around in the other directories and I see no other executable. I've even tried liberally spreading SOME_TEXT.TXT around in case I missed a directory. Any ideas?

I have the following code:

string path = "SOME_TEXT.TXT";
ifstream txtFile;
txtFile.open(path, ifstream::in);
char line[200];
if(txtFile.is_open())
{
    int lineNumber = 1;
    while(!txtFile.eof())
    {
        txtFile.getline(line, 200);
        Line * ln = new Line(line, path, lineNumber);
        lineNumber++;
        myList.addLine(ln);
    }
}
myList.printAll();
1

1 Answer 1

1

You can control the working directory your program will run at in properties in the context menu of your project. Then in the "Debug" tab.

This directory defaults to the output directory of the executable. Note that the output directory for release and debug are different. They are typically called "Debug" and "Release".

Try to stick your text file in the Debug folder.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I used that to see that I needed the file in the solutions directory not the Debug folder which is counter-intuitive. As long as it works and I can Debug that's all that matters.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.