在C / C ++中查找当前的工作目录
在本节中,我们将看到如何使用C或C++获取当前的工作目录。我们为当前操作系统定义了一些标志。
范例程式码
#ifdef WINDOWS
#include <direct.h>
#define GetCurrentDir _getcwd
#else
#include <unistd.h>
#define GetCurrentDir getcwd
#endif
#include<iostream>
using namespace std;
std::string get_current_dir() {
char buff[FILENAME_MAX]; //create string buffer to hold path
GetCurrentDir( buff, FILENAME_MAX );
string current_working_dir(buff);
return current_working_dir;
}
main() {
cout << get_current_dir() << endl;
}输出结果
D:\C++ Programs\section 53
热门推荐
8 敏字的祝福语简短
10 朋友弟弟生日祝福语简短
11 對好友毕业祝福语简短
12 创业大吉祝福语简短
13 对司机的祝福语简短
14 红包祝福语简短网名
15 女性生日祝福语简短优美
16 初八的祝福语简短
17 祝福语对联文案简短大气
18 给儿子生日祝福语 简短