Possible Duplicate:
how to find the location of the executable in C
I'm writting an multi-platform app in C++ using GTK+ and I have a problem. I must get program path. E.g., when program is in /home/user/program
(or C:\Users\user\program.exe
), i have /home/user/
(or C:\Users\user\
).
Can and how I can do this?
argv[0]
contains the program name with path. Am I missing something here?For Win32/MFC c++ programs:
Also observe the remarks at http://msdn.microsoft.com/en-us/library/windows/desktop/ms683156%28v=vs.85%29.aspx,
In essence: WinMain does not include the program name in lpCmdLine, main(), wmain() and _tmain() should have it at argv[0], but:
On windows..
Linux
And you should look at this question..
How do I get the directory that a program is running from?