Hi,
Now ive got the dynamic memory sorted. Is there any function / class in the c++ std that returns the path of the working directory.(the path of the directory which the application is in)
Cheers
Alex
Hi,
Now ive got the dynamic memory sorted. Is there any function / class in the c++ std that returns the path of the working directory.(the path of the directory which the application is in)
Cheers
Alex
One way is to use the first argument when defining main with command line arguments support. It gives you the full path of the executable.
Read http://www.cprogramming.com/tutorial/lesson14.html
Originally Posted by brewbuck:
Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.
>> It gives you the full path of the executable.
That is not necessarily true. Often only the executable name is available (as your link points out).
Getting the working directory is a platform specific operation, so what OS and compiler are you using?
well for the current project win32 visualc++Originally Posted by Daved
Edit: I found a func: getcwd(), seems to work on linux, win32 & solaris
-Alex
Last edited by appleGuy; 08-28-2006 at 03:45 PM.
getcwd() is a POSIX function, so it should work on quite a few systems.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
>I found a func: getcwd()
Are you looking for the current working directory of the user, or the directory in which the executable resides?
Yup. My bad. And I just checked and mingw doesn't give the full path. So, I have no idea why I was convinced that to be true.Originally Posted by Daved
Originally Posted by brewbuck:
Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.
http://msdn.microsoft.com/library/de...lefilename.asp
http://msdn.microsoft.com/library/de...lebasename.asp
one retrieves the path with the file name the other just the file name.. figure it out.
EDIT:
there...Code:TCHAR FileName[MAX_PATH] = {0}; TCHAR FilePath[MAX_PATH] = {0}; GetModuleFileNameEx(GetCurrentProcess(), NULL, (LPWSTR)&FilePath, MAX_PATH); GetModuleBaseName(GetCurrentProcess(), NULL, (LPWSTR)&FileName, MAX_PATH); size_t FP = wcslen((wchar_t*)&FilePath); size_t FN = wcslen((wchar_t*)&FileName); FilePath[FP-FN] = L'\0';
Last edited by mrafcho001; 08-28-2006 at 08:01 PM.
That's how you get the true name of the executable, but I think the OP was looking for getcwd():
Of course, you could call GetModuleFileName() and strip off the file name itself to get the directory.Is there any function / class in the c++ std that returns the path of the working directory.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
Note: these are NOT the same!Originally Posted by appleGuy
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
You can change the working directory, or the program can start in a different directory than that which the executable is in. (Try it: right-click, create shortcut, right-click, properties and you can change the working directory.)
Which one you want (working or executable directory) depends on what you're trying to do.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.