get current directory cpp

To get the current directory in C++, you can use the following steps:

  1. Include the necessary header files:
#include <iostream>
#include <filesystem>
  1. Use the std::filesystem namespace to get the current path:
std::filesystem::path currentPath = std::filesystem::current_path();
  1. Convert the path to a string using the string() method:
std::string currentPathString = currentPath.string();
  1. Output the current directory path:
std::cout << "Current directory: " << currentPathString << std::endl;