在C ++中更改当前工作目录 [英] Change the current working directory in C++
问题描述
如何以平台不可知的方式在C ++中更改当前的工作目录? 我找到 direct.h
与Windows兼容的头文件,以及与UNIX / POSIX兼容的 unistd.h
。
_chdir
,但存在一个别名 chdir
。) 这两个实现在成功时返回零,错误时返回-1。正如你可以在manpage中看到的那样,在POSIX变体中可能会出现更多不同的errno值,但这对大多数用例来说应该没有什么不同。
How can I change my current working directory in C++ in a platform-agnostic way?
I found the direct.h
header file, which is Windows compatible, and the unistd.h
, which is UNIX/POSIX compatible.
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.
这篇关于在C ++中更改当前工作目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!