views:

66

answers:

2

I am writing code that opens an istream object on a file specified by the user. I want to be able to run the program in the debugger and just type the filename (eg data.txt) at the prompt, not the whole path. I haven't worked out how to do this inside the IDE so I have been saving my .txt file to the debug folder and running the .exe file, but that means I can't step through the program. How do I make it work inside the IDE instead? Thanks.

A: 

I am not sure I understand exactly the problem - is it that your data file is part of the project, but is not in the executable folder when you access it, or is it that the datafile is at another location? If the former, and the data file is part of the project, right-click on the file, and set the Build Action property to "Content". That way, it will get copied to the bin/debug folder where the executable runs when you debug.

cdonner
Thanks for replying - it turns out my problem was to do with not having set the working directory for the debugger (or alternatively my problem was having saved the txt files in the wrong place, depending on how you look it at). I do appreciate you trying to help me out though, and your advice will be useful for when I'm adding data files to projects in future. Thanks.
pocketdora
+1  A: 

you can set the working path of the executable (project properties->Debugging->Working Directory), which leads the debugger to start the executable with that path as working directory. This has the advantage that if you set the same path for all your configurations (Debug/Release/...), you only need 1 data.txt on your entire system, which is especially nice if you want to change data.txt or it's name.

stijn
Thanks - this fixed it. The IDE was looking in the default folder (which turns out to be the same folder as the project file is in) whereas I had my various data files saved one level down in the debug folder for that project. I set project properties->Debugging->Working Directory to the debug folder for the project and after that my program was able to access the files just from me typing in the filename at the prompt. Yay!
pocketdora