I have a prog in c:\prog\prog.exe
whats the easiest way to get it to read c:\prog\prog.ini without actually telling it the path.
so that if i moved both files to c:\prog2\
the exe would read c:\prog2\prog.ini
thanks
Printable View
I have a prog in c:\prog\prog.exe
whats the easiest way to get it to read c:\prog\prog.ini without actually telling it the path.
so that if i moved both files to c:\prog2\
the exe would read c:\prog2\prog.ini
thanks
I belive if you this,
the program will open the file in that directory the program is running from.Code:fstream file("prog.ini", ios::in);
Note however that this doesn't work if you use the PATH variable or explicit path specification to launch your app.
Great, now I'm making you nervous :D
Suffice to say, directory support in the standard C++ library is bad.
You can always retrieve the path to the program with the GetModuleFileName() API call, if you need to.
You can also retrieve the path + filename like this,
It's just a matter of removing the filename and you have the path to where the program is located.Code:#include <iostream>
#include <stdlib.h>
main(int argc, char * argv[])
{
cout << " *argv << endl;
system("PAUSE");
return 0;
}
But even so, I believe you'll run into problems if your program's directory is in the PATH variable, and you simply invoked it with "prog-name".Quote:
Originally posted by laasunde
You can also retrieve the path + filename like this,
It's just a matter of removing the filename and you have the path to where the program is located.Code:#include <iostream>
#include <cstdlib>
main(int argc, char * argv[])
{
std::cout << " *argv << std::endl;
std::system("PAUSE");
return 0;
}
Zach L. : Never heard of that but then again Im new to c++ programming. Thanks for the info :)