get current directory cpp
To get the current directory in C++, you can use the following steps:
- Include the necessary header files:
#include <iostream>
#include <filesystem>
- Use the
std::filesystem
namespace to get the current path:
std::filesystem::path currentPath = std::filesystem::current_path();
- Convert the path to a string using the
string()
method:
std::string currentPathString = currentPath.string();
- Output the current directory path:
std::cout << "Current directory: " << currentPathString << std::endl;