এই সেকশনে আমরা দেখব কিভাবে সি বা সি++-এ বর্তমান ওয়ার্কিং ডিরেক্টরি পেতে যায়। আমরা বর্তমান অপারেটিং সিস্টেমের জন্য কিছু ফ্ল্যাগ সংজ্ঞায়িত করেছি।
উদাহরণ কোড
#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