![]() |
The current working directory, also known as the present working directory, is the location on the file system where the executing program is located and operates from. When working with files and directories in C++, it is important to determine the current working directory to find the resource files. In this article, we will learn how to get the current directory in C++. Get Current Working Directory in C++To get the current working directory in C++, we can use the getcwd() function provided by the <direct.h>header. Below is the syntax to use the getcwd function: Syntax of getcwd()char *_getcwd(char *buffer, size_t size); where:
C++ Program to get Current Working Directory in Windows Based SystemsThe following program illustrates how we can get the current working directory in windows using getcwd function in C++:
Current working directory: C:\Users\Desktop Time Complexity: O(1) Get Current Directory with std::filesystem MethodWe can also find the current directory using the new std::filesystem::current_path() method which was introduced in C++17. C++ Program to get Current Working Directory using FilesystemThe following program illustrates how we can get the current working directory using std::filesystem::current_path() function in C++:
Current working directory: C:\Users\Desktop Time Complexity: O(1) |
Reffered: https://www.geeksforgeeks.org
C++ |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 22 |