Visual Studio won't read text files?

So I'm developing in C++ with the latest version of Visual Studio Desktop, however it refuses to open any text file unless it is in the same directory as the source file. It doesn't matter if I explicitly tell it to look somewhere else, it won't find it unless it's in the same directory as the source file. However if I run the executable without visual studio, it can find it just fine. It's only when visual studio runs it. Can someone tell me why this is? And possibly how to fix it?
Alright well i used to have this problem myself but first what is your o/s
I'm running windows 7 with the latest service pack.
alright well for me it was all about how i was looking for it like the following help alot

fstream inout(C:\\Users\\ whatever

because for somereall alot of times the compiler wont find it unless it is very very spacific when it is outside of the source folder

but do you have a line of code youd like to post to get a better idea of waht is going on program wise
The "issue" is, the working directory isn't equivalent to the exe directory when run from VS.

Think of a project like this:

Project
-> Debug
---> program.exe
-> Release
---> program.exe
-> main.cpp


Think about opening a file from the program:
If you use both Debug and Release modes (you will, someday), it will look from the Project directory.
This allows to have some consistency when running from Debug/Release mode without having to copy files over from a directory to the other.

If you really had files in program.exe's directory, you will have to copy all the files to the other directory for the final compile.

If you don't want this to happen, open the Project's properties, and under Debug, change the Working Directory to the one you wish to use.
Last edited on
Topic archived. No new replies allowed.