

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find out the current working directory in C/C++
In this section, we will see how to get the current working directory using C or C++. We have defined some flags for the current operating system.
Example Code
#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; }
Output
D:\C++ Programs\section 53
- Related Questions & Answers
- Get the Current Working Directory in Java
- How to set the current working directory in Python?
- Java Program to Get Current Working Directory
- How to know current working directory in Python?
- How to display the current working directory in the Linux system?
- How can we find out the current transaction mode in MySQL?
- How to find current directory of program execution in Python?
- How to change the shell working directory in Linux?
- How to get the current username and directory in Golang?
- How to change current directory using Python?
- How to change the root directory of the current process in Python?
- C++ Program to find out the total price
- How to know/change current directory in Python shell?
- Specifying working directory while executing FM SXPG_COMMAND_EXECUTE in SAP system
- Program to Find Out the Minimum Parsing Tree in C++
Advertisements