-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpath.cpp
More file actions
executable file
·44 lines (37 loc) · 1002 Bytes
/
path.cpp
File metadata and controls
executable file
·44 lines (37 loc) · 1002 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// [!] For linux
#include <iostream>
#include <string>
#include <unistd.h>
#include <limits.h>
std::string getCurrentWorkingDirectory() {
char temp[PATH_MAX];
if (getcwd(temp, PATH_MAX) != NULL) {
return std::string(temp);
} else {
// Handle error
return "";
}
}
int main() {
std::string currentDirectory = getCurrentWorkingDirectory();
std::cout << "Current working directory: " << currentDirectory << std::endl;
return 0;
}
// [!] For windows
// #include <iostream>
// #include <string>
// #include <windows.h>
// std::string getCurrentWorkingDirectory() {
// char temp[MAX_PATH];
// if (GetCurrentDirectory(MAX_PATH, temp)) {
// return std::string(temp);
// } else {
// // Handle error
// return "";
// }
// }
// int main() {
// std::string currentDirectory = getCurrentWorkingDirectory();
// std::cout << "Current working directory: " << currentDirectory << std::endl;
// return 0;
// }