I use fstream to read/write file in C++.
The structure of my project is:
project
/folder
source.cpp
source.o
source.out
data.txt
Makefile
My code to read file look like this:
ifstream f;
f.open("data.txt"); // because source.out is same directory with data.txt
But it can’t read this file if I run it in Eclipse. It only work if I put data.txt file like this:
project
/folder
source.cpp
source.o
source.out
Makefile
data.txt
It’s not good. I also don’t want to fix my code to:
f.open("folder/data.txt")
when they are in same directory. Because if I run source.out outside eclipse, it doesn’t work.
Anybody can give me some solutions?
You can set the “working directory” in the run configuration (arguments tab)