इस सेक्शन में, हम देखेंगे कि 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]; // पाथ रखने के लिए स्ट्रिंग बफर बनाएं
GetCurrentDir(buff, FILENAME_MAX);
string current_working_dir(buff);
return current_working_dir;
}
main() {
cout << get_current_dir() << endl;
}
आउटपुट
D:\C++ Programs\section 53