Date file addresses on other computers

Hello. I've been working on an application that reads and writes to a data file. I have everything working fine except that when other computers try to use it, they can not find the file. How can I change my program to read the file in the same folder as it regardless of the computer it's on. In case it matters, all the computers in question are Windows operated. Thank you in advance.
> I have everything working fine except that when other computers try to use it, they can not find the file.
Huh?

You run your program on machine A and create data.dat

You copy data.dat to machine B, in the same relative location as it was on machine A

You run your program on machine B and you can't see data.dat?

OR

Are you expecting machine B to read the file on machine A through some act of magic?


Possible that he means that the file is not being saved in the same location. If you simply do:

1
2
std::ifstream inFile;
inFile.open("alas.txt");


Then it'll look for the file in the SAME directory as the .exe .

If you do something like this:

1
2
std::ifstream inFile;
inFile.open("C:\\users\\zapshe\\Desktop\\alas.txt");


Then it'll be computer specific since other computers wont have the file in that same exact directory (usernames will be different, the drive Windows is installed on might be different.)
Then it'll look for the file in the SAME directory as the .exe .

It will look in the current working directory, which is not necessarily the same as where the exe is.
It will look in the current working directory, which is not necessarily the same as where the exe is.

If he runs it off the .exe then it'll be the directory of the exe. Only time it wont be the same directory (that I'm aware of) is when you're running the code, in which case it'll be the directory of the .cpp file. I assumed he is running off an .exe since that's the easiest way to move around an application.
It depends on how the computers are connected.
you may be able to call the subst command via system to map the remote target to a common location eg z:\ and get it that way. Do you have the remote folder shared? The first step, really, is to access the file yourself via windows explorer to prove that your network and sharing are set up right. From there, share it one way or another and you can open it.
Last edited on
If he runs it off the .exe then it'll be the directory of the exe.
No it'll be in the current working directory. If you run a program from the command line, that's whatever directory you're in when you run it. If you run it by clicking on an icon, it's whatever directory the shortcut has in the "Start In" field.

The bottom line is that the current working directory and the location of the exe are independent of each other.
No it'll be in the current working directory.

I wonder where the working directory will be when you run it off the .exe directly... could it be the same place the .exe is? He's on Windows, why would he be opening it from a command line? And the part about the shortcut is false. It would still be in the directory of the original .exe - that's where the shortcut leads.

EDIT: Misread what you said about the shortcut, but it doesn't contradict what I said. The "start in" directory is automatically the directory of the .exe . Sure, working directory and .exe location can be different, but you'd have to go out of your way to make it so. I doubt the OP is trying that hard to get in his own way.
Last edited on
Topic archived. No new replies allowed.