Last active
July 5, 2025 08:19
-
-
Save sidewinder040/4dd96b763e5aa2bd17d37b51f86dfe76 to your computer and use it in GitHub Desktop.
C++17 - Get Current Working Directory Path
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdlib> | |
#include <iostream> | |
#include <string> | |
std::string getHomeDirectory() { | |
const char* home = std::getenv("HOME"); | |
if (home == nullptr) { | |
throw std::runtime_error("HOME environment variable not set"); | |
} | |
return std::string(home); | |
} | |
int main() { | |
std::string configPath = getHomeDirectory() + "/.myapp/config.conf"; | |
std::cout << "Config Directory: " | |
<< configPath | |
<< std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment