In a program I open a file say file.dat
at runtime. The problem is when i run the executable it expects the file to be in the directory from where it is executed. I want the program to look into the same directory where the executable is present. What modifications should I make in my program (or in the build system).
For example consider this program:
int main()
{
std::ifstream ip("file.dat");
// do something.
return 0;
}
I am working on Ubuntu with g++-4.6 compiler and CMake build system. Since the project supports out-of-source build that means the program executable can be anywhere depending upon the directory where the cmake
was invoked from.
Thanks for the help...