This is normal, to open a file you have to tell the system where to look. It defaults to the current working directory which from an IDE is the directory that the exe exists in and from a command prompt is the directory it is showing as the current directory.
If you want to open a file located elsewhere you will need to use an absolute or relative path to the file.
From the beginning i thought that "current working directory" means the courrent directory of the "exe" file! But now i realize it is not true!!!
for example: the code in Alien's first post. suppose the .exe file and the data.txt file are in "c:\xyz" folder.
If i run the exe in this way:
C:\xyz>Alien.exe it works ok.(here command prompt current directory is c:\xyz)
but if i try to run it in this way:
C:\>xyz\Alien.exe it does not work!!(here command prompt current directory is c:\, but the exe and the txt file are in same directory)
Now this is not that problem if someone is working in command prompt (one can simply go to that directory....). But it is really a problem when I want to run that Alien.exe file from another code using
system("xyz\\Al ien.exe"); or
system("c:\\xyz \\Alien.exe"); command. It does not work!! when the
Alien.exe runs it does not looks for the
data.txt file in C:\xyz folder instead it looks for the current directory where the main exe (in which i m calling the system command) is!
Here my question is : is there anything i can do in the main code so that when i call the system(); command and run Alien.exe, The Alien.exe will get
C:\xyz as its current working directory?