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();
Pete
  • 10,651
  • 9
  • 52
  • 74
  • 1
    Why don't you print out the directory the program is running from? See e.g. http://stackoverflow.com/questions/143174/c-c-how-to-obtain-the-full-path-of-current-directory – Tony Delroy Apr 04 '11 at 05:16

1 Answers1

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.

Arvid
  • 10,915
  • 1
  • 32
  • 40
  • 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. – Pete Apr 04 '11 at 05:35