C++ Current Directory

Started by
6 comments, last by beefsteak 19 years, 6 months ago
Hey How do I get the current directory I'm working in, in C++? I've seen a function called getcurdir() or something like that, which is found in dir.h. I've using Visual Stuio 6 and there is no dir.h? Is there another way to get it? Thanks
The ability to succeed is the ability to adapt
Advertisement
just use GetModuleFileName from the win32 API

something like:

char lpFilename[255];
memset( lpFilename, 0, 255 );
GetModuleFileName( AfxGetInstanceHandle(),lpFilename, MAX_PATH );

should do it.
yet, another stupid signature..
There is getcwd(buffer,size) in direct.h (win32) or unistd.h (unix)
Current working directory and application paths are not always the same.
Thanks

-----
a2ps

Do I have to include anything to use those functions?

------
Anonymous Poster

It says in the reference that direct.h includes dir.h. I don't have dir.h though?
The ability to succeed is the ability to adapt
What about "GetCurrentDirectory"?
I've used that some times to get my app's directory and it worked well. AFAIK, the function doesn't bring any dependencies other than "windows.h".

This looks promising and the easiest. Just one thing though. Can I use it in a console app?
The ability to succeed is the ability to adapt
Should be no problem to call it from a console application.

This topic is closed to new replies.

Advertisement