I have a C++ project that reads information from .txt files. Everything has been running properly when I debug in Eclipse but when I run the application outside of eclipse using the debug .exe it can't find the text files. This is because Eclipse isn't building the text files in the debug folder (Not sure why it runs when I debug inside of eclipse then).
I have a folder in my project that contains all my text files and that entire folder isn't being built in the /Debug folder. I've had a look around some file properties and options like "Exclude from build" haven't been ticked. I've no idea where else to check.
Any ideas?
C++ compilers don't interact with .txt
files, those files are loaded dynamically during run time.
I believe your issue is that your putting the file name in your executable relative to where the program is running. That can be an issue as your program could run in different location when eclipse launches it.
Example:
Project File
Bin
Executable.exe
Program.cpp
text.txt
If you have this type of structure, and you run your program through tool it might make the working directory set to Project File
and so the relative path to text file would be text.txt
. But if you were to launch the program from inside the bin
file than the relative path to the text file would be ..\\text.txt
An ease solution to this is to place the text.txt
file in both the bin
file and the project file
or don't use relative path
but use absoulte path
Absoulte path
is when you write down the path starting from the root like so C:\\Project File\\text.txt
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.