Code::Blocks Forums
User forums => Using Code::Blocks => Topic started by: Crumbler on September 16, 2020, 08:49:50 pm
-
I'm writing a program using C++.
In one of my functions I need to open a .txt file using an std::ifstream.
This file is supposed to be located in the same folder as the executable.
I'm using a relative path.
However when launching my program directly from CodeBlocks, it can't find the file.
If I copy the .txt file into ...\bin\Debug and launch the executable manually, it works just fine.
Absolute paths work fine from CodeBlocks.
How can I make the relative path work when launching my program directly from CodeBlocks?
-
You must go to Project -> Properties -> Buil targets and set "Execution working dir" to bin\Debug
-
Thanks, this works for me.
Though I still have to get the text file copied to the folder when I build the project.
I used a post-build step with a cmd command:
cmd /c copy $(PROJECTDIR)\fShader.txt $(TARGET_OUTPUT_DIR)
cmd /c copy $(PROJECTDIR)\vShader.txt $(TARGET_OUTPUT_DIR)
Is there any way to do that more elegantly?
-
If your program does not modify the files you need to copy them only once.
-
Set the Execution working dir to the directory where the files reside, this way you dont need to copy them around.