Read/write directory problems.

I wrote a c++ program that reads in some data files in the current directory. After user input it will also generate an output file in the current directory.

It works fine, until I try to put it on a webserver. All the directory address stuff gets out of hand and nothing works. Doesn't seem like there is a lot of help on the net.

My questions are:

- Is there a way to link these data files directly to the program itself? They aren't very big, about 20MB. This way I can skip over the directory addressing problem.

- How do I get the program to output the file into a specific directory, rather than just it's current directory? I'd like to store files into a subfolder, for example.

I use fstream for the input files and ostream/filebuf for the output file.
Thank you in advance.
For question 1, if it is not possible, how do I force the program to look for these data files in the directory of the program file itself, rather than the start location? I'm using JSP to call the program via system command line.
For those interested in the answer, declare you main function like this:

int main(int argc, char *argv[])

where argc = argument count, argv = argument.
you can add your own argument if you want. They are all separated by space.

The point is however, argv[0] is your program call. Example could be:

"c:\users\bar\foo\foo.exe"

Truncate the foo.exe part and store this to a string to use an absolute path.
Append folder names or whatever to get desired location.

Hope this helps.
Topic archived. No new replies allowed.