"lallous" <la*****@lgwm.org> wrote in message
news:2f************@uni-berlin.de...
Specify the full path instead of just the file name, as:
fstream f("i:\\c++projects\\yourfile.txt", ios::binary);
You can also usually also use .. as in
fstream f("..\\lib\\yourfile.txt", ios::binary);
But these types of details are outside the scope of C++, which knows nothing
about directories. Note that these directories are usually relative to: (1)
if running from the command line then the directory from which you ran the
program (which may be different from the directory the program lives in),
(2) in Windows the the Start In property which you can see when you right
click the file.
To avoid harcoding directory names you can use the the standard C function
getenv to get an environment variable by name. But this design requires the
existence of an environment variable, which comes with its own hassles,
especially in the install script. You can also require the user to specify
a config file in the command line which you can retrieve from argv[i]. The
config file often hard codes absolute directory names.
int main(int argc, char * * argv);
int main(int argc, char * * argv, char * * env); // the 3rd argument 'env'
is non-standard, but many compilers support it