在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
热门推荐
10 喜事敬酒祝福语简短精辟
11 生病祝福语简短文案
12 浪漫的生日祝福语简短
13 圣诞饭店祝福语大全简短
14 周末思念祝福语大全简短
15 班级集体生日祝福语简短
16 生日祝福语大全女生简短
17 周末祝福语正能量简短
18 农民朋友发财祝福语简短