sparkFinder sparkFinder - 1 year ago 129
C++ Question

C: Change the current working directory

I'm trying to figure out a way where I can change my current output directory using C++ code - and also need that method to be platform agnostic.

I found the direct.h header file which is Windows compatible, and the unistd.h which is UNIX/POSIX compatible. Any solutions?


Answer Source

The chdir function works on both POSIX (manpage) and Windows (called _chdir there but an alias chdir exists).

Both implementations return zero on success and -1 on error. As you can see in the manpage, more distinguished errno values are possible in the POSIX variant, but that shouldn't really make a difference for most use cases.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download